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; }