in reply to returning nested data structures

What you may not know about the return function is that it evaluates its parameter(s) in the context of the subroutine invocation.

If you called the subroutine like this: $f= sub(...) then %filters will be evaluated in a scalar context and return a string that shows some statistics of the hash, but no values of the hash itself.

To rectify this you can do one of two things: Return a reference to the hash instead of the hash, i.e. "return \%filters;". Or change the call context, i.e. "%f= sub(...)". The second method copies the complete hash and should be avoided if the hash is really big