in reply to Text parsing. Processing scopes and subscopes.

See perlretut and Can I use Perl regular expressions to match balanced text?.

But first, think about what you are doing. What you seek to do is not simple. Unless this is a homework assignment, I would reconsider the problem and approach it differently. If you are parsing a known format such as XML or HTML then you should use an existing module. If you are parsing a file you created then you should create it with a tree structure instead.

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Text parsing. Processing scopes and subscopes.
by shawnhcorey (Friar) on Aug 26, 2015 at 12:54 UTC

    Agreed. Unbounded nested scoping requires a state machine with a stack. Every time a new scope is encountered, the current state of the machine is pushed onto the stack and when it ends, the saved stated is popped off.