use strict; END { print "END\n" }; { package SubRef; use Scalar::Util qw(weaken refaddr); sub DESTROY { my $self = shift; print "DESTROY ".ref($self) ."\n" } sub new { my $class = shift; my $copy; my $self = $copy = bless(sub { $copy->ok }, $class); weaken $copy; return $self; } sub ok { print "SubRef ok ".refaddr($_[0])."\n" } } { package ArrayRef; @ArrayRef::ISA = qw(SubRef); sub new { my $class = shift; return bless [], $class; } } { package CircularRef; @CircularRef::ISA = qw(SubRef); sub new { my $class = shift; my $s = {}; $s->{self} = $s; return bless $s, $class; } } for (1..2) { my $sub = SubRef->new; my $sub2 = SubRef->new; my $arr = ArrayRef->new; my $cir = CircularRef->new; $sub->(); $sub2->(); } print "After For\n";