my $f = \&foo; *foo = sub { print "in foo()\n"; return &$f; } foo(); __output__ in foo() in foo() ... and so on