Please read
this first.
How can I force the internal perl representation to be two-byte utf-8, ... ?
Encode the string of characters.
use Devel::Peek;
my $str = "\326";
Dump $str; # not UTF-8 (1 char is 1 byte)
my $utf8 = $str;
utf8::upgrade($utf8);
Dump $utf8; # upgraded to UTF-8 (1 char is 2 bytes)
my $utf8_as_bytes = $str;
utf8::encode($utf8_as_bytes);
Dump $utf8_as_bytes; # not UTF-8 (2 chars with 1 byte each)
__END__
SV = PV(0x8519228) at 0x8061e38
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x852b250 "\326"\0
CUR = 1
LEN = 4
SV = PV(0x84556a0) at 0x8528b40
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
PV = 0x852b290 "\303\226"\0 [UTF8 "\x{d6}"]
CUR = 2
LEN = 3
SV = PV(0x84556a8) at 0x8528730
REFCNT = 1
FLAGS = (PADMY,POK,pPOK)
PV = 0x852b2a0 "\303\226"\0
CUR = 2
LEN = 3