in reply to Look behind and global
When performing s///g substitutions, the regexp engine does all the matching on the original unaltered string, and makes a copy on which to perform all the substitutions. So in this case, all the matches are looking at "12345", and at each position from offset 2 onwards it successfully finds that it is "just after two digits".
In this case, the simplest way to achieve the desired effect is to have the digits be part of the match rather than perceived only as part of a zero-width assertion:
$x =~ s/(\d{2})/$1\n/g;
Hugo
|
|---|