in reply to Re^2: Problems Handling UCS-2LE
in thread Problems Handling UCS-2LE

Indeed! That shouldn't happen. Or at the very least, it's inconsistent with UTF-16.

$ perl -le'open $fh, "<:encoding(UTF-16le)", \"\xFF\xFE"; print length + <$fh>' 1 $ perl -le'open $fh, "<:encoding(UTF-16)", \"\xFF\xFE"; print length < +$fh>' 0 $ perl -le'open $fh, "<:encoding(UCS-2le)", \"\xFF\xFE"; print length +<$fh>' 1 $ perl -le'open $fh, "<:encoding(UCS-2)", \"\xFF\xFE"; print length <$ +fh>' UCS-2BE:Unicode character fffe is illegal at -e line 1.

Using File::BOM or the following would be a better solutions than skipping the first two bytes.

$lines =~ s/\x{FEFF}//g;