in reply to help to write perl code

This or if you prefer, linked as this : YAML module should greatly help you, I have started giving it a good look for configuration file parsing purposes and it might very well be the perfect tool for your task.

also, as said before you should first think about writing a script to spot and correct the xml syntax errors in your input file
Cheers!

Update, another link better formatted this time that will complete your toolchain : xml2yaml