in reply to recursive algorithm for nested data structures

#!/usr/bin/perl use 5.010; use strict; use warnings; use YAML; use Regexp::Grammars; my $str = <<'EOT'; (root (class living_thing (spec human (prop has_legs)) (spec bird (prop has_wings)))) EOT my $parser = qr{ ^ <List> $ <rule: List> (?: \( <[MATCH=Atom]>* \) ) <rule: Atom> <MATCH=List> | <MATCH=Word> <token: Word> \w+ }x; print Dump $/{List} if $str =~ /$parser/; __END__ --- - root - - class - living_thing - - spec - human - - prop - has_legs - - spec - bird - - prop - has_wings