my $count; while (<$fh_r>) { if (my $status = /START/ .. /END/) { $count++ if $status == 1; print if $count == 2; } }