$pattern = 'match'; @array = ('hello', 'matched', 'match', 123, 'sleep'); foreach (@array) { # Matched 'match' but not 'matched' print "$1\n" if /\b($pattern)\b/; #print "$1\n" if /(\b$pattern\b)/; }