in reply to Re^2: counting inside the loop
in thread counting inside the loop

AnomalousMonk explains in Re^2: counting inside the loop, use  my $count = () = m/ab/g;

Replies are listed 'Best First'.
Re^4: counting inside the loop
by sarvan (Sexton) on Jul 04, 2011 at 05:19 UTC
    Hi,
    $s='finding related pages finding on the world wide web'; my $count=$s=~ m/finding/g; print $count;

    I expect the result as 2.. becus "finding" exists two times in $s. but the output is 1. Why??

    thanks

      It is because you don't know how to copy/paste

      The extra  ( ) = are required --- probably the worst syntax in all of perl, but its what you need if you have built-in regexes without objects, and you don't store matches in an array.