http://www.perlmonks.org?node_id=308289


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.