You could speed things by shuffling @words right before the two inner loops.
foreach my $i (1..$cards) {
my %seen;
.
.
.
for my $x (1..4) {
for my $y (1..4) {
my $word;
while (1) {
my $index = rand(@words);
$word = $words[$index];
if (!$seen{$word}) {
$seen{$word}++;
last;
}
}
.
.
.
becomes:
use Algorithm::Numerical::Shuffle qw /shuffle/;
.
.
.
foreach my $i (1..$cards) {
.
.
.
@words = shuffle @words;
for my $x (1..4) {
for my $y (1..4) {
my $word = shift @words;
.
.
.
HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.