in reply to Compare two lists of words

To find if a word $a is in a string $b you can use a regex to match a word boundary, the word you are looking for and a word boundary: $b =~ /\b$a\b/;.

You can have Perl build such a regex using the words of your array by joining the words with the pipe symbol to seperate the alternatives. (You will have to group this part of the regex to require the word boundaries on either side of a word.)

Using the regex Perl built for you, you can grep through the strings in @B to find the number of times there's a match, leading to:

$words = join '|' => @A; if (grep /\b(?:$words)\b/, @B) { # do this } else { # do that }

— Arien

Edit: To just find out if there is a match, it is faster to use a loop and break out of it (after setting a flag) when you find a match like fruiture does.