in reply to Re^2: Find number of short words in long word
in thread Find number of short words in long word

... and if it's something you need to fix, you can do so easily by packing everything but the first character into a look-ahead:
my $count =()= 'abrabrabrabra' =~ /b(?=rabra)/g;

Of course in this case you know that the first possible overlap starts at the second be, so even /bra(?=bra)/ works fine.

(I haven't benchmarked it, but I suppose that non-look-around literals are a bit faster, due to optimizations regarding the match length).

Replies are listed 'Best First'.
Re^4: Find number of short words in long word
by AnomalousMonk (Archbishop) on Jul 14, 2009 at 23:37 UTC
    No need to split the string-to-be-searched-for up into first character/rest of the characters if the capture group is wrapped in a look-ahead.
    >perl -wMstrict -le "my $string = 'aBrabRabrAbra'; my $pattern = qr{ brabra }xmsi; my $count =()= $string =~ m{ (?= ($pattern)) }xmsg; print $count; my @matches = $string =~ m{ (?= ($pattern)) }xmsg; print qq{@matches}; " 3 BrabRa bRabrA brAbra