#!/usr/local/bin/perl -w use strict; my @names = ("John?", "Paul", "George", "Rin.go"); my $regexStr = "^static\\s+\\w+\\s+(" # Thanks moritz! . (join "|",map quotemeta,@names) . ")\\W.*"; print "$regexStr\n\n"; my $regexStr_rr = qr{$regexStr}i; # or "cloister" the 'i' in $regexStr while() { chomp; my ( $hit ) = $_ =~ /$regexStr_rr/; if ($hit) { print "Beatle method \"$hit\" found on this line: $_\n"; } else { print "No Beatle method found on this line: $_\n"; } } __DATA__ static int lars(...); static bool george(...); static int thom(...);