in reply to Regex variable capturing gotcha

perldoc perlre:
The numbered match variables ($1, $2, $3, etc.) and the related + punctu- ation set ($+, $&, $`, $', and $^N) are all dynamically scoped +until the end of the enclosing block or until the next successful mat +ch, whichever comes first. (See "Compound Statements" in perlsyn.) NOTE: failed matches in Perl do not reset the match variables, +which makes easier to write code that tests for a series of more spec +ific cases and remembers the best match.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.