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