in reply to Regex Find Words
my $left_text = [ qw{ when rome romans} ]; my $right_text = 'When in Rome, do as the Romans.'; my $regex = join '|', map quotemeta, @$left_text; $regex = qr{\b(?:$regex)\b}i; my $found = () = $right_text =~ m/$regex/g; print $found, $/;
The $found = () = trick first sets the RHS in list context, and then by obtains the number of elements in the list.
|
|---|