use strict; my $max = 200; #number of elements for array my @array = (0..$max-1); #initialize array while(@array !=0){ my $index = rand @array; #pick a random element of the existing array my $element = $array[$index]; #extract the element my @newarray = grep {$_ !=$element} @array; #remove the element @array = @newarray; #reset the array }