in reply to frame shift in Perl string matching

Use a look ahead assertion:

my $str = "PPPP"; my $search = "PP"; my $count = () = $str =~ /(?=$search)/g; print $count;
True laziness is hard work

Replies are listed 'Best First'.
Re^2: frame shift in Perl string matching
by GTI (Initiate) on Oct 09, 2012 at 05:12 UTC

    Thanks!