in reply to Efficient Comparison of Array elements

I would not call this efficient. I have concerns regarding this scaling up, but I've not yet had reason to check it out.
This does seen to be the kind of idiomatic solution you implied you wanted.

UPDATE: More details on the data set being manipulated make me more cautious about the suitability of this code. If efficiency is really a problem and the differences and intersection of the arrays are all desired my first question would be Are these arrays ordered, as in your example?

#!/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