If the data structure is complex and especially if it is somewhat arbitrary, such that you do not wish to mirror the complexity of the data-structure in the complexity of your code, it's a good idea to look at
http://search.cpan.org for the keys
diver and
walker.