in reply to Text parsing. Processing scopes and subscopes.
In addition, may I suggest that you consider using an existing templating tool, such as Template::Toolkit? Although often used for creating HTML pages, it can in fact be used for anything. Although you can “roll your own” solution here, maybe this is an all-around better way to do it. Much more bang for your buck, and nothing to create.