in reply to Regexes: finding ALL matches (including overlap)

From the top of my head:
$count = () = map /y/g, /<.*?>/g;
A little more complex, but possibly a little more memory friendly, is:
use List::Util 'sum'; $count = sum map { my $x = () = /y/g } /<.*?>/g;

Replies are listed 'Best First'.
Re^2: Regexes: finding ALL matches (including overlap)
by kaif (Friar) on Jun 04, 2005 at 18:07 UTC

    Very nice! In fact, the first time I looked at it, I thought it wouldn't work, because I misunderstood what it did; playing around with it convinced me it worked, however.

      I forgot to mention my mistakes:
      1. I confused /y/g with the y// transliteration operator.
      2. I forgot map provided list context.