http://qs1969.pair.com?node_id=11148257


in reply to Global match and capture group in look-ahead == under-populated "@-"?

https://perldoc.perl.org/perlvar#@-

edit

It's hard to tell which result you expect, but the way pos is changed after replacing a zero length assertion is tricky. It's meant to avoid endless loops.

use v5.12; use warnings; use Data::Dump 'dd'; $_ = 'aa'; s/(?=(a))(?{say "\$1='$1' \@-=(@-) pos=",pos})/b/g; dd [$1]; dd \@-; dd $_; __END__ $1='a' @-=(0 0) pos=0 $1='a' @-=(0 0) pos=0 $1='a' @-=(1 1) pos=1 $1='a' @-=(1 1) pos=1 ["a"] [1] "baba"

update

this may shed some light

use v5.12; use warnings; use Data::Dump 'dd'; $_ = 'ab'; s/(?=([ab]))(?{say "\$1='$1' \@-=(@-) pos=",pos})/X/g; dd [$1]; dd \@-; dd $_; __END__ $1='a' @-=(0 0) pos=0 $1='a' @-=(0 0) pos=0 $1='b' @-=(1 1) pos=1 $1='b' @-=(1 1) pos=1 ["b"] [1, 1] "XaXb"

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery