#!/usr/local/bin/perl -w use strict; my @names = ("john", "paul", "george", "ringo"); while() { chomp; my $hit = 0; foreach my $name (@names) { if (m/^static\s+\w+\s+(${name})\W.*/) { $hit = $1; last; } } if ($hit) { print "Beatle method \"$hit\" found on this line: $_\n"; } else { print "No Beatle method found on this line: $_\n"; } } #### while() { chomp; if (m/^static\s+\w+\s+($names[0]|$names[1]|$names[2])\W.*/) { print "Beatle method \"$1\" found on this line: $_\n"; } else { print "No Beatle method found on this line: $_\n"; } } #### # Note that this line isn't supposed to compile... if (m/^static\s+\w+\s+(???@names???)\W.*/) { #### static int lars(...); static bool george(...); static int thom(...); #### No Beatle method found on this line: static int lars(...); Beatle method "george" found on this line: static bool george(...); No Beatle method found on this line: static int thom(...);