use strict; use warnings; my $doFoo = main->can ('foo'); print $doFoo ? $doFoo->() : "Can't foo\n"; sub foo { return 1; }