Personally, I wouldn't consider it a bug, but rather a constraint on the use of capturing parens and references to captures in the context of the "g" modifier: the "$1,$2,..." can only be used reliably in the replacement side of s///g, and cannot be counted on as defined outside the scope of that operator.