sub format_string { my ($str) = @_; return $str if ! $str; my $new_str = ''; for my $chr (split '', $str) { my $ord = ord($chr); if ($ord < 255) { $new_str .= $chr; next; } $new_str .= '&#x' . sprintf("%x", $ord) . ';'; } return $new_str; }