in reply to Turning off buffering ($|=1) doesn't work on Apache server

In early 1.3 versions of Apache - it was enough to simply do $| = 1. In later versions - and especially in Apache 2 versions you must flush the buffer your self. Your example above would turn into the following:
#!/usr/bin/perl use strict; my $r = Apache->request; # mod_perl 1 print "Content-type: text/html\n\n"; print "<html><head></head><body>"; print "START\n"; $r->rflush; sleep 5; print "End\n"; print "</body></html>\n";


If you want everything to be buffered I would make a sub like the following:
my $my_print = sub { print @_; $r->rflush; }; # call it like this $my_print->("<html><head>....");

If your script is going to be migrating from CGI to mod_perl 1 to mod_perl 2 I would recommend using the CGI::Ex module which lets you handle all three without modifying your script.
#!/usr/bin/perl use strict; use warnings; use CGI::Ex; my $cgix = CGI::Ex->new; my $my_flush; if (! $cgix->mod_perl_version) { $| = 1; $my_flush = sub {}; # no op } else { $my_flush = sub { # works on most apache versions $cgix->apache_request->rflush; }; } $cgix->print_content_type; print "<html>...\n"; $my_flush->(); sleep 5; print "The rest...\n";


my @a=qw(random brilliant braindead); print $a[rand(@a)];