#!/usr/bin/perl use warnings; use strict; my @one = ( 1, 2, 3, 4); my @two = ( 2, 4, 6, 8); my (%in_one, %in_two, @in_both, @only_in_one, @only_in_two); @in_one{ @one} = 1; @in_two{ @two} = 1; @in_both = grep { exists $in_one{$_} } @two; @only_in_one = grep { not exists $in_two{$_}} @one; @only_in_two = grep { not exists $in_one{$_}} @two; local $, = " "; print "\@one ", @one, "\n"; print "\@two ", @two, "\n"; print "\@only_in_one ", @only_in_one, "\n"; print "\@only_in_two ", @only_in_two, "\n"; print "\@in_both ", @in_both, "\n"; __DATA__ @one 1 2 3 4 @two 2 4 6 8 @only_in_one 1 3 @only_in_two 6 8 @in_both 2 4