Well, certainly Perl’s regular expressions are pretty powerful in the first place, and this task really wouldn’t be that difficult with hand-written code, but we can go a bit further and pull out a nifty tool from the CPAN: the “madman of Perl” Damian Conway’s Parse::RecDescent. This module permits extremely complex parsers to be built by specifying a nice hierarchical description of the data (as a grammar), and a series of actions to be taken as each portion of the data is returned. I find it very simple to use, and whipped up a parser in no time.