use Pegex; $tree = pegex($grammar, receiver => 'Pegex::Tree::Wrap')->parse($input);
Pegex::Tree is receiver class that will shape the captured data from a Pegex parse operation into a tree made out of hashes. The keys of the hashes are the rule names that matched, and the values are arrays of captured data.
This module is not often used as a receiver base class, but it is the default receiver for a Pegex parse. That's because the tree is very readble with all the rule keys in it.