in reply to Replacing all but one duplicate lines


To do this you could modify your while loop as follows:
my $i = 0; while (<FILE>) { $temp .= $_ unless /$heading_to_print/ and $i++; }
Your code suggests that you want to make the changes "in-place". You could do it all in a one-liner as follows:     perl -i.bak -ne 'print unless /pattern/ and $i++' file Enjoy your vacation. :-)

--
John.