#!/usr/bin/perl use warnings; use strict; my @temp1 = qw( test test1 test test2 test2 test ); print "----------------------\nContents of Temp1 Array\n"; print map "\t$_\n", @temp1; my @temp2 = qw( test1 test2 test2 ); print "----------------------\nContents of Temp2 Array\n"; print map "\t$_\n", @temp2; my %temp1; $temp1{ $_ }++ for @temp1; my %temp2; $temp2{ $_ }++ for @temp2; print "----------------------\nThe (Unique) Intersection of Temp1 and Temp2 Arrays\n"; for my $key ( grep exists( $temp2{ $_ } ), keys %temp1 ) { my $count = $temp2{ $key } < $temp1{ $key } ? $temp2{ $key } : $temp1{ $key }; print map "\t$_\n", ( $key ) x $count; }