use strict; use warnings; use vars qw/$AUTOLOAD/; sub AUTOLOAD { $AUTOLOAD =~ /.*::(.*)/; my $name = $1; print "It looks like you're trying to call $name...\n"; no strict 'refs'; *{ "main::$name" } = sub { print "Hey, I've been called by ", (caller)[0], ", and here my arguments: @_\n"; }; goto &{ "main::$name" }; # The brand new sub can't realize it has # been actually called from somewhere # else } foo( "Hello", "World" ); foo( "Howdy, world" ); # I call foo() again, this time it exists sub bar { foo( "See you, world" ); } bar();