#!/usr/bin/perl -w use strict; my @a = qw(a b c e); my @b = qw(a b c d g); compare1 (\@a,\@b); compare2 (\@a,\@b); sub compare1 { my ($aref, $bref) = @_; my %a = map{$_=>0}@$aref; my %b = map{$_=>0}@$bref; foreach (keys %a) { $a{$_}++ if (exists ($b{$_})); } foreach (keys %b) { $b{$_}++ if (exists $a{$_}); } foreach (keys %a) { print "$_ does not exist in B\n" if !$a{$_}; } foreach (keys %b) { print "$_ does not exist in A\n" if !$b{$_}; } } sub compare2 { my ($aref, $bref) = @_; my @a = @$aref; my @b = @$bref; while (@a || @b) { my ($compa, $compb) = (shift @a, shift @b); $compa = 'undefined' if (!defined($compa)); $compb = 'undefined' if (!defined($compb)); if ($compa ne $compb) { print "$compa and $compb do not match\n"; } } } __END__ e does not exist in B g does not exist in A d does not exist in A e and d do not match undefined and g do not match