in reply to Re^4: finding neighbors of an element in arrays
in thread finding neighbors of an element in arrays

Ok, your script is nearly there, but you need to be able to store many neighbors for each element, so instead of a hash you need a HashofHashes, see perllol. Just change lines like $h{$element}=$domains1[1]; and replace them with $h{$element}{$domains1[1]}++;

Why do I have the impression this is just homework? Maybe because a similar question, just with words instead of domains, was posted inside an hour of this one.