#!/usr/bin/perl -w use strict; sub common { my (%common, %test); $_ = shift; @common{@$_} = {} x @$_; # second use is scalar context while ( $_ = shift) { %test = (); @test{@$_} = () x @$_; delete @common{ grep { ! exists $test{$_} } keys %common}; } return ( keys %common ); } my @foo = ( [1,2,3,5,8,9,4,5], [18,2,4,7,3,4.9], [2,3,6,5,9], [1,2,3,4,5,6,7,8,9,0], [1,2,3,5,8], [2,3,4,5,8,7], ); print "@{[common(@foo)]}$/";