in reply to Re: Re: $1 doesn't reset?
in thread $1 doesn't reset?

alfie, my understanding is this (and I'm relying on more knowledgable monks to correct me if I'm misunderstanding):

Working with $_, not $1, is the correct behaviour in the for loop. Because:
- the regexp match produces a list
- the for(each) loop cycles through each element of the list, assigning them to $_ as it goes.

So... $1 doesn't contain each match in turn, because the regexp is only executed once, and the matches are put into $1 to $n, and into a list, and the loop goes round the list, aliasing $_ to each element in turn.

If you want to use $1, then Corion's suggestion of \G should do the biz. But it looks to me as though the for loop and $_ would be more efficient.

andy.