Thank you all! Algorithm::EquivalenceSets is perfect.
Unfortunately I broke it when trying to install with CPAN. Devel::CheckOS is a pre-req and I think I accidentally hit "no" when I should have hit "yes" (it asked if I was running unix directly after asking if I was running linux! how was I supposed to know the correct answer was "yes"??). Anyway, now it won't let me install it. "clean Devel::CheckOS" doesn't appear to work. Oh well, I'll figure it out eventually. Thanks again for all your help.