http://qs321.pair.com?node_id=246641


in reply to Special Variable Pattern Match whilst reading input from a file

Parenthesised matches always end up in the match variables $1, $2, ..., so you could write:

while (<CONFIG_FILE>) { if (/^frz\s+=\s+(\w+);/) {$bar=$1} }

If you have more than one pair of parenthesis, $1 will refer to the match of the first pair, $2 to the second and so on. The pairs are ordered from left to right, counting their opening parenthesis, so:

"abc123def"=~/([a-z]+(\d+)(.*))/; print "first: $1\nsecond: $2\nthird: $3\n";
would print:
first: abc123def
second: 123
third: def

-- 
        dakkar - Mobilis in mobile