my $i = 0; while () { $temp .= $_ unless /$heading_to_print/ and $i++; } #### perl -i.bak -ne 'print unless /pattern/ and $i++' file