my @indices = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, rand()] } 0 .. $#arr; my @subset = @arr[@indices[0..$number_to_show - 1]];