for(1..5){ my $r = rand @array; push @subset,$array[$r]; $array[$r] = $array[-1]; pop @array; }