use utf8;
use Encode;
open $out, ">:perlio:encoding(UTF-16)", "out.txt";
print $out "hoge\x0d\x0ahoge\n";
close $out;

open $in,"<:bytes","out.txt";
local $/=undef;
my $a = <$in>;
$a =~ s/([\x00-\x20\%\x80-\xff])/'%'.unpack('H2',$1)/ge;
print $a;