sub Intersection { my ($refA, $refB) = @_; my %B; @B{@$refB} = (1) x @$refB; # hash the second list my $intersects; for(@$refA) { ++$intersects if exists $B{$_} # 'exists' is fast! } return $intersects; }