#!/usr/bin/perl -w use strict; while (<>) { chomp; #call Sam 'the ____ hobbit' my @sam_list = qw(nasty rude mean); my $sam_descr = $sam_list[int rand scalar(@sam_list)]; s/\bSam\b/the $sam_descr hobbit/ig; #replace 's' at word's end with 'ses' s/([a-rt-z]{3,})s(\b)/$1ses$2/ig; #replace 's' at word's start or middle with 'sss' s/(\b\w*)[sS]([a-df-z]+\b)/$1sss$2/ig; s/\bme\b/us/ig; #call Frodo 'Master' s/\bFrodo\b/Master/ig; #replace second-person words with third-person 'it' s/your/its/ig; s/\byou\b/it/ig; s/\bare\b/is/ig; s/have/has/ig; #replace past-tense words with present-tense s/was/is/ig; s/(\b\w{3,})ed(\b)/$1s$2/ig; #replace 'i ' with 'i s' naively s/^i\s(\w{4,})\b/I $1s/ig; s/\bdo\b/does/ig; #replace first-person words with third-person my @i_list = qw(we smeagol); my $i_descr = $i_list[int rand scalar(@i_list)]; s/\bi\b/$i_descr/ig; #stick a generic ending on the end (no if negatives) my $ending = ""; $ending = "no" if (m/(not)|(no)/); my @endings = ("","yess","my precioussss", "gollum"); $ending = $endings [int rand scalar(@endings)] unless ($ending eq "no"); $_ .= " $ending"; #capitalize the sentence $_ = ucfirst($_); print $_, "\n"; }