$names = 'Fred Flintstone and Wilma Flintstone'; if ($names =~ m/(?\w+) and \w+ \g{last_name}/) { print "I saw $+{last_name}\n"; }