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


in reply to $1 not "freezing" in an addition

Does it work better if you "unreverse" the if condition?
if(s/\(#:(\d+)\)/#/) { return $1 + distance($_); }

As I don't have the whole code, it's a bit difficult to test. And it's just a hunch.