use Encode qw( is_utf8 encode_utf8 ); is_utf8($string) ? encode_utf8($string) : $string