sub foo { my $bar = sub { print "world!\n" }; print "Hello\n"; &$bar; #also can be written as: $bar->(); } foo(); #&$bar here will not work since $bar is only valid inside foo.