We operate a b2b mailing list, which over the years has grown to many thousands of members.

I want to clean this list out, and remove duplicate company e-mail addresses. I'm not just talking about exact duplicates, i.e. x@y.com and x@y.com, as my software does this already. What I mean, is that I want to keep only one for each server e.g. if x@company1.com has subscribed, eveything else such as y@company1.com is deleted. Furthermore, if a company tries to subscribe with another e-mail address, when it has already subscribed, this should not be permitted.

This seems simple enogh, but I've been pulling my hair out searching google and various cgi sites for ages without any results. Any ideas?