my $flag; while(<$fh>){ chomp; if (/this/) { $flag = 1; next;} elsif (/^\s*$/) {$flag = 0;} print "$_\n" if $flag; } close($fh);