my $i = 0; while () { $temp .= $_ unless /$heading_to_print/ and $i++; }