If you can describe a yacc-like grammer for this, you may be interested in Parse::RecDescent, which would pull all of this into Perl for you. I don't have much experience with it, but for complex or nested data, it's usually going to be easier to use than, say, Perl regular expressions at getting at this data.