LINE: while ( ) { for my $word ( @words ) { my $pat = $regex{$word}; next unless ( /$pat/ ); print "$word was found\n"; last LINE; } }