sub validUTF8{ ($_)=@_; use utf8; my @a=split "",$_; foreach (@a) { # if (/[\0-\x{ff}]/ or /[\x{C0}-\x{C3}][\x{80}-\x{FF}]/){ if (/[\0-\x{ff}]/ or /[\x{C2}-\x{C3}][\x{80}-\x{FF}]/){ } else { print STDERR "BAD:$_\n"; no utf8; return 0; } } no utf8; return 1; } #converts from utf8 to latin1 #### sub utf8tolatin1 { ($_)=@_; use utf8; tr/\0-\x{ff}//UC; #change utf8 to Latin-1 no utf8; return $_; } #converts from latin1 to utf8 sub latin1toutf8 { ($_)=@_; use utf8; tr/\0-\0xff//CU; #change Latin-1 to utf8 no utf8; return $_; }