#!perl -w # usage: perl latin2eight.pl INFILE OUTFILE use strict; my($in,$out) = @ARGV; open(IN,$in) or die "cannot open $in $!"; open(OUT,">$out") or die "cannot open $out $!"; binmode OUT; # use utf8; # treat input as utf8 characters, not byte series. use Unicode::String 'latin1', 'utf8'; # ,'byteswap2', 'utf16'; # $firstString = utf8($firstString); # print OUT byteswap2($firstString->utf16); # stick the BOM at the beginning, as a hint that this is a UTF8 file. my $bom = Unicode::String->new(); $bom->chr(0xfeff); print OUT $bom; # this is the bom. :-) # print all remaining lines. while () { my($u) = latin1($_); print OUT $u->utf8; } close(IN) or die "cannot close $in $!"; close(OUT) or die "cannot close $out $!";