$h{$_}++ for (@array1,@array2); @common_elements = grep {$h{$_} > 1} keys %h; print "@common_elements";