#!/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"; } }