Derive ü
from s///
and into your own variable so that we can test it.
use utf8; # Script is encoded using UTF-8 use open ':std', ':encoding(UTF-8)'; # Terminal expects UTF-8. use strict; use warnings; my $uuml = "ü"; printf("%d %vX %s", length($uuml), $uuml, $uuml); # 1 FC ü my $fuer = pack('H*', '66c3bc72'); printf("%d %vX %s", length($fuer), $fuer, $fuer); # 4 66.C3.BC.72 für $fuer =~ s/\Q$uuml/!!!/; printf("%d %vX %s", length($fuer), $fuer, $fuer); # 4 66.C3.BC.72 für
As this is obvious, you are comparing the Unicode ü
( FC
) Code Point against the UTF-8 ü
( C3 BC
) encoding.
So yes, use utf8;
indicates that the script is encoded using UTF-8 ... but it does so so that Perl can correctly decode the script.
Decode all inputs and encode all outputs! The solution is to replace
my $fuer = pack('H*', '66c3bc72');
from
use Encode qw( decode_utf8 ); my $fuer = decode_utf8(pack('H*', '66c3bc72'));
or
my $fuer = pack('H*', '66c3bc72'); utf8::decode($fuer);
source share