#!/usr/bin/perl -w use strict; use diagnostics; { my $cache = [Foo->new]; sub access_cache { return \@$cache; } } foreach (@{&access_cache()}) { print STDERR "before: ", ref($_), "\n"; print STDERR "object: ", $_, "\n";; print STDERR "after: ", ref($_), "\n\n"; } foreach (@{&access_cache()}) { print STDERR "before: ", ref($_), "\n"; print STDERR "object: ", $_, "\n"; print STDERR "after: ", ref($_), "\n"; } package Foo; sub new {bless [], $_[0]}; use overload '""' => sub {$_[0] = Bar->new; return $_[0]->[0]}; package Bar; sub new {bless ['barbar'], $_[0]}; use overload '""' => sub {return $_[0]->[0]};