in reply to Finding out which of a list of patterns matched

while ( <DATA> ) { if ( /(foo)|(bar)|(baz)/ ) { print "Found $+ line $.\n"; last; } } __DATA__ Stuff The quick brown baz jumps over the lazy bar foo

Update: Here's a complete programme. Enter the name(s) of the text file(s) on the command line.

use strict; use warnings; die "Usage: $0 filename(s)\n" unless @ARGV; my @to_match = qw ( foo bar baz 43 q\uux ); # or whatever my $match = join ')|(', map quotemeta, @to_match; while ( <> ) { if ( /($match)/ ) { print "Found '$+' in $ARGV line $.\n"; close ARGV; } $. = 0 if eof; }