for (my $i = @list; -- $i;) { my $r = int rand (1 + $i); @list [$i, $r] = @list [$r, $i] unless $r == $i; }