my $rln = /$start_re/ .. /$end_re/; if $rln == 1 { # open output file next; } if $rln > 1 { print $out_fh $_; } #### if rindex($rln, 'E0') { close $out_fh; next; }