#! perl -slw use strict; use Time::HiRes qw[ time ]; our $A //= 1e6; our $B //= 1e5; my @alphas = 'aaa'..'zzz'; my @numers = '0'..'9'; print "Gening data..."; my @a = map{ $alphas[ rand @alphas] . $numers[rand @numers] } 1 .. $A; my @b = map{ $alphas[ rand @alphas] . $numers[rand @numers] } 1 .. $B; my @c = 1 .. @b; print "Starting..."; my $start = time; print "Indexing..."; ## index array @a my %a; undef $a{ $_ } for @a; print "Removing..."; for my $i ( reverse 0 .. $#b ) { exists $a{ $b[ $i ] } and delete $b[$i] and delete $c[$i]; } printf "Took %.6f seconds to check %d (\@b) against %d (\@a) and remove %d items\n", time() - $start, $B, $A, $B - @b __END__ C:\test>962209 -A=1e6 -B=1e5 Gening data... Starting... Indexing... Removing... Took 0.771435 seconds to check 100000 (@b) against 1000000 (@a) and remove 198 items