You might want to take a look at Parse::RecDescent, which was made to do heavy parsing like this. It isn't exactly a speed demon, however; so you might to look at other parsing methods as well. Japhy has a section in his upcoming regex book, Regular Expressions in Perl, about this. Ironically enough, its titled Parsing a Language. Take a look, its good stuff.