in reply to Printing and Removing Duplicates in Arrays

Similar to thor's solution above--no greps--but this one'll also wipe out the dupes from your arrays:
use strict; my @a = (0,1,2,3,4,5,6,7,8,9); my @b = (0,1,4); my @isect = (); my @diff = (); my %count = (); foreach my $e (@a) { $count{$e} = 1; } foreach my $e (@b) { $count{$e} += 2; } @a = @b = (); foreach my $e (keys %count) { if ($count{$e} == 1) {push @a, $e;} elsif ($count{$e} == 2) {push @b, $e;} else {print "$e ";} }
For a bunch of good examples of this kind of stuff, try the Perl Cookbook, recipes 4.6 & 4.8.