if ($text =~ /(?\b$pattern1\b)|(?\b$pattern2\b)/) { foreach my $foo (keys %+) {print $foo.','.$+{$foo}."\n";} }