my $record = "a" . $record; # prepend the ID of the default charset my @parts = split /\x1B/, $record; foreach my $part (@parts) { my $charset = substr( $part,0,1,''); $charset = $ESC{$charset}; # to get the name from the id $part = decode( $charset, $part); } $record = join '', @parts;