my $my_print = sub { print @_; $r->rflush; }; # call it like this $my_print->("....");