## Taken from perlfaq4 (thanks btrott) sub fisher_yates_shuffle { my $array = shift; for (my $i = @$array; --$i; ) { my $j = int rand ($i+1); # next if $i == $j; # original if ($i == $j) { # this means the letter will be the same as it was before $i++; # put $i back where it was and get another one next; } @$array[$i, $j] = @$array[$j, $i]; } return join '', @$array; }