# store a reference to a sub my $coderef = sub { print shift || "Foo"; print "\n"; }; # execute code, with or without arguments $coderef->(); $coderef->('Bar'); $coderef->();