in reply to Help for generating multiple file from singl e file and parsing it.

A more formally defined parser system such as Parse::RecDescent might be useful here.

In essence, systems like these let you define a grammar which stipulates the valid constructs in the file, and what is to be done as each construct is recognized.   The parser is constructed and executed on-the-fly by code that is known to be highly reliable.