package Top; sub new { my $class = shift; my $s = bless { }, $class; $s->{bottom} = Bottom->new( $s ); return $s; } #===================================== package Bottom; use Scalar::Util 'weaken'; sub new { my ($class, $top) = @_; my $s = bless { top => $top }, $class; weaken($s->{top}); return $s; } #===================================== package main; use strict; use warnings 'all'; use Devel::Cycle; my $top = Top->new(); my $bottom = $top->{bottom} or die "NO BOTTOM!"; $top = $bottom->{top} or die "NO TOP!"; find_cycle( $top ); find_cycle( $bottom );