sub default_handler { print OUT "@@@ main::$_[0](\$tree) @@@\n"; recurse($_[1]); } sub dispatch { ref $_[0] eq 'ARRAY' ? \&startrule : $main::{$_[0]} || \&default_handler; } sub startrule { my $tree = shift; ref eq 'ARRAY' and dispatch($_->[0])->($_) foreach @$tree; }