use strict; # Put some phrases in an array for us to test my @phrases = (" APIblahblah", "blah APINblah", "blahUWI ."); # Match on each phrase my $phrase; foreach $phrase (@phrases) { # Do a match - note the brackets around the entire expression. # Brackets are used as a memory # See a Regular Exp guide for more info if ($phrase =~ m/(\bAPI|APIN|UWI\s*\.)/) { # If it matched we are here... $1 prints the memory of what # matched inside the brackets. Similarly if there was a # 2nd set of parentheses $2 would contain their match etc. print "Phrase: $phrase, matched on: $1\n"; # Rather than printing it here you could call your sub... # e.g. # somesub($1); } }