sub convertoUtf{ my $your_data = shift; my $encoding = 'ISO-8859-1'; if ($encoding ne 'UTF-8'){ my $ustr = Unicode::String->new(); if ($encoding eq 'UTF-16'){ $ustr->utf16( $your_data ); }else{ my $map = Unicode::Map->new( $encoding ); if (! $map ){ # Deal with the unsupported encoding somehow; # you probably want to have a message like this: # "Unsupported XML encoding: $encoding"); } $ustr->utf16( $map->to_unicode( $your_data ) ); } $your_data = $ustr->utf8(); } return $your_data; }