my $foundend; while () { next unless my $where = /START/ .. ($foundend=/END/); # ... } print "found\n" if $foundend.