use strict; use Encode; my %encoding = ( JAP => 'shiftjis', RUS => 'cp1251', # and so on... # (figure out the actual encoding names for each "clue") ); binmode STDOUT, ":utf8"; while (<>) { my $decoded = ''; for my $lang ( keys %encoding ) { if ( /$lang/ ) { # might need to be careful about how to match for language # e.g. split into fields with Text::xSV, and test one field $decoded = decode( $encoding{$lang}, $_ ); last; } } if ( $decoded eq '' ) { warn "no language discernable at line $.\n"; $decoded = decode( 'cp1252', $_ ); # assume Latin1 as a default } print $decoded; }