in reply to Leaking Regex Captures

I agree with your expected output, and that perl gives you a wrong result. I'm not competent enough to comment on your analysis, though.

Update and of course I'm wrong. See jwkrahn's reply below. Ouch.

I'm already thinking in terms of Perl 6, where the $0, $1, $2 etc. are aliases into the match object in $/. There you can't get $2 or so leaking from the previous match, and everything is pretty much transparent.