my $size = -s $filename; $size = 128 if $size > 128; my $test; open IN, $filename or die $!; read IN, $test, $size; seek IN, 0, 0; my @bytes = unpack 'C*', $test; my $nullhibytes = 0; for ( my $i=o $i<$size; $i+=2 ) { $nullhibytes++ if ( $bytes[$i+1] == 0 and $bytes[$i] =~ /[ -~]/); } if ( $nullhibytes > 8 ) { # this is probably a utf16 file (if it's text at all) } close IN;