use strict; use warnings; use Encode; use File::BOM qw(:all); use open IN => ':via(File::BOM)'; my $enc = "UCS-2"; my $str = "\x{ABCD} a b c d"; my $buf = $enc2bom{$enc} . encode($enc, $str); open(my $FH, "<", \$buf) or die $!; my $read = <$FH>; print($read eq $str ? "match" : "no match", "\n"); __END__ match