Compute a checksum for each file, and use the checksum as a key into a hash. The value of the hash will be an array (reference) storing the filenames that match that checksum. Then you can compare the contents of all the files with the same checksum.