#!/usr/bin/perl # https://perlmonks.org/?node_id=1221711 use strict; use warnings; my $pattern = "art adj{0,2} noun adverb{0,1} verb art adj{0,2} noun.\n"; my %words; while( ) { my ($word, $part) = /(\S+)\s+(\S+)/ or next; push $words{$part}->@*, $word; } for (1 .. 3 + rand 10) { print ucfirst $pattern =~ s/(\w+)(?:\{(\d+),(\d+)\})?/ my @avail = $words{$1}->@*; join ' ', map { $avail[rand @avail] } $2 ? 1 .. $2 + int $3 - $2 : 1 /ger } __DATA__ abnormal adj blah adj crazy adj dolt noun dolthead noun doltish adj doltishly adverb doltishness adj eccentric adj fallacious adj galling adj hapless adj illogical adj jabber verb kooky adj lame adj misguided adj nuisance noun officious adj pretense noun questionable adj resentful adj shaky adj tenuous adj the art a art untenable adj vague adj warp verb yawn verb zombie noun