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