$s ='a123456789'; $p = 0; print "a($1)($2)\n" while ++$p and $s =~ m[^a(.{$p})(.)]; a(1)(2) a(12)(3) a(123)(4) a(1234)(5) a(12345)(6) a(123456)(7) a(1234567)(8) a(12345678)(9)