Just an (almost) meta comment: Trying to do something like this with a single regexp is when you may start getting into "Now you have two problems" territory. As has been shown you can do this in one pass with deep regex engine magic, but were I to do it I'd instead break it down into a simple state machine and parse things line-by-line that way instead. And were the "language" being handled much more complicated then I'd look to use a proper parser module (Parse::RecDescent, maybe Marpa::R2) and let that write the state machine. If/when things change about the "language" I just would need to update the higher level grammar description instead of manually monkeying in more states.
The cake is a lie.
The cake is a lie.
The cake is a lie.