use strict; use warnings; my $word = "aaaaa"; my @words; { push @words, $word if $word =~ tr/bumps// == 2 and $word =~ tr/seam// == 2 and $word =~ tr/domes// == 3 and $word =~ tr/shake// == 3 and $word =~ tr/pokes// == 3 and $word =~ tr/dukes// == 3; last if $word eq "zzzzz"; $word = inc_letter($word, 4); redo; } print "$_\n" for @words; sub inc_letter { my ($word, $i) = @_; if (substr($word, $i, 1) eq "z") { $word = inc_letter($word, $i-1, 1); substr($word, $i, 1) = substr($word, $i-1, 1); } else { substr($word, $i, 1)++; } $word; }