in reply to
Perl and Context Free Grammar
You may want to have a look at
Parse::RandGen
. Not used it myself so can't comment on it's reliability etc but from the documentation it looks ideal for your purpose.
Comment on
Re: Perl and Context Free Grammar
In Section
Seekers of Perl Wisdom