http://www.perlmonks.org?node_id=244603


in reply to Parsing... possible w/o too much stress ?

$_=qq{ env { {}{} {{}} } }; (my $re=$_)=~s/((\{)|(\})|.)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs +; $re = join'|',map{quotemeta}eval{/$re/}; die $@ if $@; print +(/env\s*\{($re)\}/)[0];