open(my $fh, '<', $filename); binmode($fh); #### open(my $fh, "<:raw:perlio", $file); # read first few bytes for a BOM or ASCII in utf(16|32) # to determine encoding binmode $fh, ":encoding($encoding)" #### open $fh, "<", $^X or die; binmode $fh; print "1: ", join(' ', PerlIO::get_layers($fh, details => 1)), "\n"; close $fh; open $fh, "<:raw:perlio", $^X or die; print "2: ", join(' ', PerlIO::get_layers($fh, details => 1)), "\n"; close $fh; #### 1: unix 4195328 crlf 4195328 2: unix 4195328 perlio 4195328