in reply to csv to xml

There are some pretty good responses here. I'll add that you do not seem to just be converting CSV to XML. If you were the following would suffice:
my (@data, @hdrs) ; for(<DATA>) { chomp; unless ($first) {@hdrs = split q~,~; $first++; next}; @data = split q~,~; print qq~<record>\n~; for(1,3) {print qq!<$hdrs[$_]> $data[$_] </$hdrs[$_]>\n!}; print qq~</record>\n~; ++$first; } __DATA__ Name,Company,Email,Phone A,X,,1111 B,Y,,0 C,Z,,2222
<record> <Company> X </Company> <Phone> 1111 </Phone> </record> <record> <Company> Y </Company> <Phone> 0 </Phone> </record> <record> <Company> Z </Company> <Phone> 2222 </Phone> </record>

What you really appear to be doing is taking some data in one format and embedding it into an XML format. There is a difference between the two. There are actually tools out there to convert XML to other formats of XML as well as tools to format XML for the browser (CSS) that might make what you appear to be doing here moot.

As for the rest of that elaborate output (really everything up to and including the tgroup tag as well as the closing tags) can be added using simple print statements like print qq~<record>\n~;. Or you could use a template module for everything but the dynamic parts of your output.

Celebrate Intellectual Diversity