my $fh = new FileHandle("< $file"); if (! $fh) { die "failed to open list file '$file': $!"; } my $marker; if (2 != read($fh, $marker, 2)) { die "Failed to read the first 2 bytes from $file"; } if ($marker eq $UNICODE_FFFE) { binmode($fh, ":encoding(utf8)"); } else { $fh->seek(0, 0); }