##
use HTML::Entities;
use Text::Iconv;
my $text = chr(256);
my $conv = Text::Iconv->new("utf8", "latin1");
$text = $conv->convert($text);
encode_entities($text);
print "$text\n";
####
$text =~ s/([^[:print:]])([^[:print:]])/
''.
((((ord($1) & 0x7F) << 6) + (ord($2) & 0x7F)) & 0x7FFF).
';'/eg;