in reply to Controlling matching position in regexes to match all proper substrings

A couple other ways:

c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; print 'Perl version ', $]; ;; my $s = 'abcd'; ;; my @captures = $s =~ m{ (?= (\w\w)) }xmsg; printf qq{'$_' } for @captures; print ''; ;; local our @caps; ()= $s =~ m{ (?: (\w\w) (?{ push @caps, [ $^N, $-[1] ] }) (*F)) }xmsg +; print qq{captured '$_->[0]' at offset $_->[1]} for @caps; " Perl version 5.014004 'ab' 'bc' 'cd' captured 'ab' at offset 0 captured 'bc' at offset 1 captured 'cd' at offset 2
Note that Perl version 5.10+ is needed only for the Special Backtracking Control Verbs  (*F) construct in the second example above. Also, the  (?{ code }) block in the second example must push to a package-global array because this construct doesn't work reliably with pad (my) variables (this was fixed in version 5.18 – I think). (Update: The first example above is very nice and neat if you only need to capture the (overlapping) matched substrings. If more info is needed, e.g., substring offset, one of the other, more messy approaches must be used.)

Update: Another version of the second example can be had that does not depend on any 5.10 regex enhancement (the example below was run under 5.8.9), but it has the quirk that (for a reason I used to know but have since forgotten) all push-es to the array are duplicated! If you can live with that, then:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "print 'Perl version ', $]; ;; my $s = 'abcd'; ;; local our @caps; ()= $s =~ m{ (?= (\w\w) (?{ push @caps, [ $^N, $-[1] ] })) }xmsg; dd \@caps; ;; my $skip; print qq{captured '$_->[0]' at offset $_->[1]} for grep $skip = !$skip, @caps; " Perl version 5.008009 [["ab", 0], ["ab", 0], ["bc", 1], ["bc", 1], ["cd", 2], ["cd", 2]] captured 'ab' at offset 0 captured 'bc' at offset 1 captured 'cd' at offset 2

Update 2: Actually, in the regex of the
    ()= $s =~ m{ (?: (\w\w) (?{ push @caps, [ $^N, $-[1] ] }) (*F)) }xmsg;
statement of the second example above, the outermost  (?: ... ) non-capturing grouping is completely useless. The
     m{ (\w\w) (?{ push @caps, [ $^N, $-[1] ] }) (*F) }xmsg
regex works just as well.