http://qs1969.pair.com?node_id=730731


in reply to How to convert <,&,>,",' into XML &lt;,&amp;,&gt;,&quot ..

May be the following conversion will satisfy you

$xml_native =~ s/([^\w\s])/'&#'.ord($1).';'/ge;