check out
ref, and learn recursion.
Data::Dumper does something like this, so does
Data::Denter. Of course both do more work that what you need, but recursion is recursion, and they're examples of it. That is all.
Also, this has nothing to do with "objects". Its a perl data structures question. Suggested reading is perldata, perldsc, perllol, and perlref.