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