#!/usr/bin/perl
use strict;
use warnings;
use Encode qw( encode from_to );
print("Content-Type: text/html; charset=utf-8\n\n");
my $name = encode('utf-16le', "\x{65E5}\x{672C}\x{8A9E}");
eval { from_to($name, 'utf-16le', 'utf-8', Encode::FB_CROAK); 1 }
or print("coaked\n");
print $name;
####
$ test.cgi | od -c
0000000 C o n t e n t - T y p e : t e
0000020 x t / h t m l ; c h a r s e t
0000040 = u t f - 8 \n \n 346 227 245 346 234 254 350 252
0000060 236
0000061
####
#!/usr/bin/perl
use strict;
use warnings;
use Encode qw( encode decode );
binmode(STDOUT, ':encoding(utf-8)');
print("Content-Type: text/html; charset=utf-8\n\n");
# Input
my $name = encode('utf-16le', "\x{65E5}\x{672C}\x{8A9E}");
eval { $name = decode('utf-16le', $name, Encode::FB_CROAK); 1 }
or print("coaked\n");
# Process
# ...
# Output
print $name;