A better pure Perl example to get ideas on how to parse is probably Text::xSV. It does handle embedded newlines. Plus the strategy of using /g matches and pos is massively easier to get your head around than big and nasty regular expressions. (And extends to more complex problems.)