in reply to Comparing records in file and reporting stats - Scenario 2
There are modules for comparing data structures.
Compare/Diff on nested data structures has pointers to some relevant modules that you might consider.