use Encode qw( encode ); $string = encode('US-ASCII', $string, Encode::FB_HTMLCREF);