As has already been said a match in scalar context with /g doesn't 'reset' pos() so that the next match with /g on that variable will start from that position.
The key error in your understanding is that "they're two completely separate regexen". They're not because they're connected by pos() since they have /g.
In first examples using ?? work just the same as the latter case with m// with the once-only nature of ?? just being an additional constraint. ?? works exactly like m// with regards to setting pos() and starting from pos() in scalar context with /g.
So the key point is that the position of the last match is being carried over between the statements, which you weren't expecting.
--
integral, resident of freenode's #perl
In reply to Re: Bizarreness in ?PATTERN? and g
by integral
in thread Bizarreness in ?PATTERN? and g
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |