in reply to XML::Simple problem, or How to convert HTML to Perl and then back again.

Is the template much more complex than the example you provide? If not, you could just concatenate the strings, i.e.

$top_of_template = qq( <html> <head> <title> test </title> </head> <body bgcolor='red' > ); $bottom_of_template = qq( <table> <tr colspan='2'> <td> text </td> <td> text2 </td> </tr> </table> </body> </html> ); $middle_of_template = (your code); $output = $top_of_template . $middle_of_template . $end_of_template;
Alternately, you could just use HTML::Template to do this same task:
<errors> <TMPL_IF NAME="INVALID_WIDGET_SIZE"><TMPL_VAR NAME="INVALID_WIDGET_SI +ZE"></TMPL_IF> <TMPL_IF NAME="INVALID_WIDGET_COLOR"><TMPL_VAR NAME="INVALID_WIDGET_C +OLOR"></TMPL_IF> </errors>

and then just pass the invalid widget color (or any other variable you'd like) (instead of a simple boolean?) and not have to worry about dealing with XML::Simple and all of its nastiness.