while() { chomp($_); $current = "$_"; while() { print OUT "$_" if ($. == $current); } seek(ORIG,0,0); }