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

pat_mc:

You might try using a zero-width positive lookahead assertion. I've not used them much, so there may be some gotchas in their general use. But for a simple usage like yours, it's not so bad:

$ cat u.pl use strict; use warnings; while ('aaa' =~/a(?=a)/g) { print $-[-1], "\n" } $ perl u.pl 0 1

Read about them in perldoc perlre in the "Look-Around Assertions" section.

...roboticus

When your only tool is a hammer, all problems look like your thumb.