sub myprint { print "MYPRINT: ", @_; } my $printfunc = $condition ? sub { print @_; } : \&myprint; $printfunc->("hello world\n");