#!/usr/bin/perl use strict; use warnings; my @a1 = qw(13470660 13471850 14028274 14028286); my @a2 = qw(14028145 14028286 13476691 13471850); my %hash; for (reverse 0..$#a1) { # Does 2 checks. To see if a number from the second array was # already seen in the first array. Also, checks to see if its # a 'reversal' or flip flop and thus a duplicate. if (exists $hash{$a2[$_]} && $hash{$a2[$_]} == $a1[$_]) { splice @a1, $_, 1; splice @a2, $_, 1; } else { $hash{$a1[$_]} = $a2[$_]; } } print "@a1\n@a2\n";