in reply to Re: Re: Local variables assigned to pattern matches
in thread Local variables assigned to pattern matches

The backreferences ($1, $2, ...) only last as to the end of the current scope, or to the next successful regex. Thus, it's pretty useful to keep them in another variable. Also, those variables are read-only, so if you need to extract something and modify it, you need another variable:
while (<>) { chomp; my ($name) = /(\w+\s+\w+)/; $name =~ tr/\n\r\t\f / /s; # squish spaces push @names, $name; }


japhy -- Perl and Regex Hacker