#!/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{ ^ $ (?: \( <[MATCH=Atom]>* \) ) | \w+ }x; print Dump $/{List} if $str =~ /$parser/; __END__ --- - root - - class - living_thing - - spec - human - - prop - has_legs - - spec - bird - - prop - has_wings