use warnings; use strict; use feature 'say'; my @strings = ( "Bob said hello\n", "Alice doesn't like Chris\n", "This line won't match\n" ); for (@strings){ say "yay!" if /(?:\bAlice\b|\bBob\b|\bChris\b)/; } #### / (?: # group, but don't capture \bAlice\b # capture Alice, if it is standalone | # or \bBob\b # same as Alice above | # or \bChris\b # same as Alice and Bob ) # end grouping /