sub intersection_length { my($h1, $h2) = ( { map { $_ => 1 } @{$_[0]} }, { map { $_ => 1 } @{$_[1]} } ); return scalar grep exists $h2->{$_}, keys %$h1; } print intersection_length([ 1 .. 5 ], [ 2 .. 6 ]), $/; __output__ 4