use Encode qw(is_utf8); # check if $str is UTF8 and contains bad UTF8. print "bad UTF8\n" if is_utf8($str) and not is_utf8($str, 1); #### iconv -c --from UTF-8 --to UTF-8 #### use Text::Iconv; my $conv = Text::Iconv->new("utf8", "utf8"); $str = $conv->convert($str);