I have an array
my @array = qw/FOO BAR BAZ/;
and a scalar read from a file containing data like
Yes, there is far better way. You can construct regular expression. It will be alternatives of fixed strings which is fortunately translated into trie (Aho-Corasick) which leads into linear search time. It is the most efficient way at all.
my @array = qw/FOO BAR BAZ/;
my $re = join '|', map quotemeta, @array;
$re = qr/$re/;
for my $string (@strings) {
if ($string =~ $re) {
...
}
}