Something like XML::Rules would build your data structure fairly easily the way you want it, but since I don't know what you want, I don't know what to write. You can start with XML::Simple and decide if that's good enough, or what you don't like, and then switch to XML::Rules.