in reply to counting overlapping patterns

Here's a bizarre way of doing it, taking a hint from my Prolog studies (thanks Ovid!):
sub match_count { my ($string, $pattern) = @_; my $n = 0; $string =~ /$pattern(?{ $n++ })(?!)/; return $n; }
Essentially, match successfully, count it, but then fail the match (an empty string can always match, so negating that always fails).

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.