in reply to regular expression.

First of all, $& will not have the whole value of line, because it holds only the string matched by the pattern match - by the last successful pattern match to be precise - this means that even if the current string doesn't match with the pattern match the value of $& will not be changed. The string value held in $& will be updated to the current successful pattern matched as soon as the pattern matches the string.

Be warned that performance is compromised if the $& variable is used any where in the program and that this variable is a read-only variable.

Secondly, since you've not provided an example of the lines that you're reading from to perform this match it is a bit unwieldy to try to replicate

$line=~/.*\sid=\"(.*)\"\slo=\"(.*)\"\sto=\"(.*)\"\srb=.*$/;
while you only need $2 then why do you wanna worry about $& in the first place?

Does your code take care of when the lines don't match with the above pattern or it generates an uninitialized variable warning when printing $2?

#maybe try something like print "$2\n\n" if $2;


Excellence is an Endeavor of Persistence. A Year-Old Monk :D .