in reply to Re: Another regex variable puzzle
in thread Another regex variable puzzle

Tested and verified. Apparently, the sections stay static, and if the string becomes shorter, the length of the string, plus one or two characters, overwrite the $<digit> variables. If you regexp again, though, they get reset as they should be. What I tried:
use re 'debug'; use strict; my (@rere,$rere); $_="hello world"; @rere = /(\w+)\s+(\w+)/; $rere = "(".join(",",@rere).")"; print "\$1 = $1, \$2 = $2, \$rere = $rere\n"; $_="foo bar"; print "\$1 = $1, \$2 = $2, \$rere = $rere\n"; @rere = /(\w+)\s+(\w+)/; $rere = "(".join(",",@rere).")"; print "\$1 = $1, \$2 = $2, \$rere = $rere\n";
with the following output:
Compiling REx `(\w+)\s+(\w+)' size 15 first at 4 1: OPEN1(3) 3: PLUS(5) 4: ALNUM(0) 5: CLOSE1(7) 7: PLUS(9) 8: SPACE(0) 9: OPEN2(11) 11: PLUS(13) 12: ALNUM(0) 13: CLOSE2(15) 15: END(0) stclass `ALNUM' plus minlen 3 Compiling REx `(\w+)\s+(\w+)' size 15 first at 4 1: OPEN1(3) 3: PLUS(5) 4: ALNUM(0) 5: CLOSE1(7) 7: PLUS(9) 8: SPACE(0) 9: OPEN2(11) 11: PLUS(13) 12: ALNUM(0) 13: CLOSE2(15) 15: END(0) stclass `ALNUM' plus minlen 3 Matching REx `(\w+)\s+(\w+)' against `hello world' [...] Match successful! $1 = hello, $2 = world, $rere = (hello,world) $1 = foo b, $2 = r rld, $rere = (hello,world) Matching REx `(\w+)\s+(\w+)' against `foo bar' [...] Match successful! $1 = foo, $2 = bar, $rere = (foo,bar) Freeing REx: `(\w+)\s+(\w+)' Freeing REx: `(\w+)\s+(\w+)'

As for the null character, that might be a byproduct of C(++) string processing -- for those who may not know, in C(++) strings are terminated with a null.