use strict; use warnings; use Devel::Peek; use Encode; use utf8; my $utfstring = "123 \x{439}\x{439}\x{439}\x{439}"; my ($ascii_but_utf, undef) = split ' ', $utfstring; my $bytestring = encode ("UTF-8", "\x{444}\x{444}\x{444}\x{444}"); my $mixedstring = "$ascii_but_utf$bytestring"; # simulate The Unicode Bug here binmode STDOUT, ":utf8"; Dump $mixedstring; print "UTF IS ON\n" if utf8::is_utf8($mixedstring); print "LENGTH DIFFERS\n" if length($mixedstring) != bytes::length($mixedstring); open my $f, ">", "test2"; binmode $f; syswrite $f, $mixedstring or die; print "ALL OK\n"; __END__ SV = PV(0x1d6eb48) at 0x1c7fab8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK,UTF8) PV = 0x1d79820 "123\303\221\302\204\303\221\302\204\303\221\302\204\303\221\302\204"\0 [UTF8 "123\x{d1}\x{84}\x{d1}\x{84}\x{d1}\x{84}\x{d1}\x{84}"] CUR = 19 LEN = 24 UTF IS ON LENGTH DIFFERS ALL OK