#!perl use 5.012; # strict, // use warnings; use Devel::Peek; open my $fo, '>:raw', 'threebytes.bin'; print {$fo} "\xEF\xBB\xBF"; close $fo; open my $fbytes, '<', 'threebytes.bin'; Dump($_ = <$fbytes>); printf "length no-encoding: %d bytes\n", length($_); printf "match no-encoding 3bytes? %s\n", m/^\xEF\xBB\xBF/ ? 'match' : 'nope'; printf "match no-encoding unicode? %s\n", m/^\x{FEFF}/ ? 'match' : 'nope'; close $fbytes; open my $futf8, '<:encoding(UTF-8)', 'threebytes.bin'; Dump($_ = <$futf8>); printf "length utf8: %d characters\n", length($_); printf "match utf8 3bytes? %s\n", m/^\xEF\xBB\xBF/ ? 'match' : 'nope'; printf "match utf8 unicode? %s\n", m/^\x{FEFF}/ ? 'match' : 'nope'; close $futf8; __END__ SV = PV(0x6ac038) at 0xb3ebe0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0xb4d308 "\357\273\277"\0 CUR = 3 LEN = 81 SV = PV(0x6ac038) at 0xb3ebe0 REFCNT = 1 FLAGS = (POK,pPOK,UTF8) PV = 0x3442c98 "\357\273\277"\0 [UTF8 "\x{feff}"] CUR = 3 LEN = 10 length no-encoding: 3 bytes match no-encoding 3bytes? match match no-encoding unicode? nope length utf8: 1 characters match utf8 3bytes? nope match utf8 unicode? match