my @words = qw/foo bar/; #your @A my @strings = ; #your @B my $contains = 0; # a boolean { my $words = join '|',map quotemeta,@words; for(@strings){ ++$contains and last if /$words/; } } print $contains ? 'yes' : 'no' , "\n" __DATA__ abc def ghi foo jkl mno