in reply to Re^2: nested replace
in thread nested replace

You probably forgot the final "; $x" in the replacement part of the outer regex. Without it, the inner substitution returns the number of times it matched.