in reply to Pattern Matching - a Tricky one

If you have control over the syntax of your text data file, read further; otherwise, stop reading now.

I do not recognize the syntax of your data being any standard syntax. However, if you could format your data according to some standard syntax, such as XML, then you could leverage the power of existing parsers, such as the CPAN module XML::Twig