my ($from_name, $to_name, $from_map, $to_map); $from_name = "cp1252.txt"; $to_name = "cp437.txt"; # Load a codepage file into a Perl data structure sub load_cp { my ($filename) = @_; my (@map); open(CP, "<$filename") || die "load_cp: $filename: $!"; while() { my ($byte, $unicode) = m/^=(..)\tU[+](....)/; $map[hex $byte] = hex($unicode); } return \@map; } # Map characters in a file from one codepage to another sub map_cp { my ($to, $from, $text) = @_; my ($new_text, $map, %to, %from, @text); # First map codepage "$from" characters to Unicode characters foreach my $char (split //, $text) { if (!defined $from->[ord $char]) { warn "no to=$to_name char for U+$char\n"; } push @text, $from->[ord $char]; } # Now map non-ASCII Unicode characters to codepage "$to" foreach my $char (@text) { if (!defined $to->[$char]) { warn "no from=$from_name char for U+$char\n"; } $new_text .= chr $to->[$char]; } return $new_text; } # Load to and from codepages $from_map = load_cp($from_name); $to_map = load_cp( $to_name); # Replace \x80 with your text print map_cp($from_map, $to_map, "\x80");