Here is my perl6 port of your code. I had to work around a thing with given/when...unless they fixed it and i didn't notice yet.
use v6;
my %dict =
(
sentence => [[qw/ noun_phrase verb_phrase /]],
noun_phrase => [[qw/ Article Noun /]],
verb_phrase => [[qw/ Verb noun_phrase /]],
Article => [qw/ the a /],
Noun => [qw/ man ball woman table/],
Verb => [qw/ hit took saw liked /]
);
sub generate ($phrase) {
given $phrase {
when .does(List) { return $phrase.map:{generate($_)} }
if (defined %dict.{$_}) { return generate( %dict.{$_}.pick) }
else { return [$phrase] }
}
}
sub gen_sentence () { generate("sentence").join(" ").say };
gen_sentence for 1..5;