hangon,
Several modules in perl 5 provide this functionality. Currently, Perl 6 will provide set operations and junctions natively. If you do not see how this answers your question I hope you go exploring for more information on your own. You never know what useful information you will find along the way.