It's probably not the best way to do it but this is what sprang to mind when I saw this post. It's also very similar to what you already have.
use strict; my @keywords = qw/foo bar 12345 abcd/; my $string = "foobarfoo1234523423412345abcdefsadfabc"; my $re = join('|',@keywords); my %result; $result{$1}++ while ($string =~ /($re)/ig); foreach my $s (keys %result){ print "$s=>$result{$s}\n"; }
In reply to Re: Count multiple pattern matches
by Mr. Muskrat
in thread Count multiple pattern matches
by johnnywang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |