When I wake up this morning, another way to do this pops onto my mind.
foreach $a (@A) {
foreach $b (@B) {
if ($a eq $b) {
...
}
}
}
cat file-A | sort | uniq > tmp
cat file-B | sort | uniq >> tmp
cat tmp | sort | uniq -d
Basically, it is a O(nlog(n)) algorithm. (the sort operation).