sub intersection{ my(%count,@res); for(map @$_,@_){$count{$_}++} for(keys %count){push @res,$_ if $count{$_}==@_} @res; } @a=intersection(\@b,\@c,\@d);