Make pos less volatile when UTF8-ness can change
This was brought up in ticket #114690.
pos checks the length of the string and then its UTF8-ness. But the
UTF8-ness is not updated by length magic. So it can get confused if
simply stringifying a match var happens to flip the UTF8 flag:
$ perl -le '"\x{100}a" =~ /(..)/; pos($1) = 2; print pos($1); "$1";
print pos($1)'
2
1
$ perl -le '"\x{100}a" =~ /(.)/; pos($1) = 2; print pos($1); "$1"; print
pos($1)'
1
Malformed UTF-8 character (unexpected end of string) in match position
at -e line 1.
0
As pointed out in that ticket, length magic on scalars cannot work
properly with UTF8, so stop using it.