http://www.perlmonks.org?node_id=305775


in reply to m//g behaves strange...

I had recently answered a post, Re: An Insane Typo Bug, and it relates to your question in an interesting way. The original post in that thread has a totally different face with your wonder, but both are about the same fact that, in scalar context, m// returns either 1 or 0.

For pos(), try this, it gives you 1 and 9, so pos() does work:

use strict; use warnings; $_ = "0123456789"; my $ret = m/0/g; print "ret = $ret, pos = " . pos() . "\n"; $ret = m/8/g; print "ret = $ret, pos = " . pos() . "\n";