#!/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 #### A misguided pretense doltishly jabber a fallacious dolthead. The crazy zombie doltishly yawn a kooky nuisance. The misguided dolthead doltishly warp a doltishness dolt. A kooky nuisance doltishly jabber a shaky zombie. A lame dolt doltishly yawn a vague zombie. The crazy dolt doltishly jabber the abnormal zombie. The resentful dolt doltishly warp a lame zombie. A crazy nuisance doltishly warp a illogical dolthead. A questionable dolthead doltishly jabber the abnormal dolthead. The illogical dolthead doltishly yawn the hapless nuisance. The galling dolthead doltishly warp the lame nuisance. A lame zombie doltishly warp the officious dolthead.