package A; sub new { my $class = shift; my $this = bless {}, $class; $this->{-twin} = new B(-twin => $this); return $this; } package B; sub new { my $class = shift; bless {@_}, $class; } $obj = new A; undef $obj; #### package A; sub new { my $class = shift; my $this = bless {}, $class; $this->{-twin} = new B(-twin => $this); return $this; } package B; sub new { my $class = shift; my $this = bless {@_}, $class; weaken $this->{-twin}; return $this; } $obj = new A; undef $obj; #### $bar = "this\nthat\n"; open(FH, '<', \$bar); $this = ; # reads "this\n" $that = ; # reads "that\n" open(FH, '>', \$bar); print FH "this\n"; print FH "that\n"; #### # $foo = capture { print 'hi'; } # $foo will be filled as if someone had done $foo = `perl -e { print 'hi'; }` or something like that # if the sub prints directly to STDOUT, like: print STDOUT 'hi'; then the output will not be captured sub capture(&) { my ($oldsel, $fh, $ret); open($fh, '>', \$ret) or die "can't capture: $!"; $oldsel = select($fh); &{$_[0]}; select $oldsel; close($fh); $ret; } #### $"=$,,$_=q>|\p4<6 8p .q>.<4-KI;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/