This will be a little incomplete. Because it would rely on your input/output specifics.
I like XML::Twig
as an alternative to XML::Simple
. Within the docs for XML::Simple
you have:
The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces.
Within the documentation for XML::Twig
you have (read above link for more, this is reproduced for convenience):
To create an element foo containing a CDATA section:
my $foo= XML::Twig::Elt->new( '#CDATA' => "content of the CDATA section")
->wrap_in( 'foo');
An attribute of '#CDATA', will create the content of the element as CDATA:
my $elt= XML::Twig::Elt->new( 'p' => { '#CDATA' => 1}, 'foo < bar');
creates an element
<p><![CDATA[foo < bar]]></>
This I think should encompass your needs?