sub common { my $num = @_; my (%common, %test); $_ = shift; @common{@$_} = () x @$_; # second use is scalar context while ( $_ = shift) { %test = (); @test{@$_} = () x @$_; delete @common{ grep { ! exists $test{$_} } keys %common}; } [ [keys %common] x $num ]; }