use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Time::HiRes qw(time); use Data::Dump qw(dump pp); my %checkFrom; my @toCheck; sub init0() {@toCheck = (); push @toCheck, rand(1e6) for 1..1e4; } sub init1() {%checkFrom = (); for my $x(0..999) {for my $y(0..999) {$checkFrom{$x}[$y] = 1e3*$x+$y; } } init0(); } sub init2() {%checkFrom = (); for my $x(0..999) {for my $y(0..999) {$checkFrom{$x}{$y} = 1e3*$x+$y; } } init0(); } for(1..10) {if (1) {init1(); my $s = time(); {my %toCheck = map { $_ => 1 } @toCheck; @$_ = grep !$toCheck{$_}, @$_ for values %checkFrom; } say "1 took ", (time() - $s); } if (2) {init2(); my $s = time(); {for my $thing (@toCheck) {for my $category (keys %checkFrom) {delete $checkFrom{$category}{$thing}; } } } say "2 took ", (time() - $s); } }