I think Test::Deep might solve your problems, or at the very least its code could give you some ideas to implement it yourself.
in reply to comparing nested data structures
Deep::Hash::Utils also gives some "easier" access to deeply nested hashes and arrays, without the need to write yourself the recursive routines.
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James