http://qs1969.pair.com?node_id=600470


in reply to How to get ($1, $2, ...)?

I very rarely use $1, $2, etc. these days, as I find they're a source of bugs for the unwary. This is mainly owing to the very special type of binding, a consequence of which is that, in the event of a failure to match, they retain their previous values.

Instead, I capture to lexical variables. In your case, a single lexical array will do:

my @answers; my $re = qr/Title: (.*?), Author: (\w+) (\w+)$/; # 3 groups here while (my @results = $text =~ /$re/mgc) { my %ans; push @answers, \@results; }

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)