use strict; use warnings; use List::Util qw{ shuffle }; use Time::HiRes qw{ time }; our $N //= 1e3; our $S //= 1e4; our $Z //= 5; my %bools = map { $_ => [] } 1 .. $N; for my $set ( 1 .. $S ) { my $conts = []; push @{ $conts }, int rand $N for 0 .. int rand $Z; push @{ $bools{ $_ } }, $conts for @{ $conts }; } my @someOrder = shuffle 1 .. $N; my $start = time(); delete @bools{ @someOrder }; printf "Took %.6f\n", time() - $start;