use Encode; # create a string with one character my $a = "\x{100}"; # create a string with two characters my $b = Encode::encode_utf8($a); # Equivalent to $b = "\x80\xc4"; print $b; # outputs the two bytes C4 80 binmode(STDOUT, ":utf8"); print $a; # outputs the two bytes C4 80 print $b; # outputs the four bytes C3 84 C2 80