You're right, it only resets them on a successful match, not on an attempted match. But it will overwrite all of them if there's a successful match, even if the match doesn't include any parens. So if the string /css/ matches, $2 will be undef, and in that case the code won't work right.