text_to_aXML: The "escape" function I posted, renamed for clarity. text_to_html: Converts & to &, < to <, etc. # Current sub d { my $text = ...; return text_to_html($text); } # Should be sub d { my $text = ...; return text_to_aXML(text_to_html($text)); }