Perl buffers output on stdout by default untill the buffer is full, or a newline is found. You can force output either by adding ',"\n"' to the end of your print statements, or by disabling output buffering by adding this line near the top:
$| = 1;
But even then it's not guaranteed that the browser will start rendering the page before it received all the content.
$| doesn't work, To make it simple, I tested following script. I expect "OK, starting time consuming process " appeared first, then "All done" aftter 5 seconds. But they all appeared all together after 5 secs.
BTW: I use apache2 with mod_perl2
#!/usr/bin/perl -wT
use strict;
$| = 1;
print "Content-type: text/plain\n\n";
print "OK, starting time consuming process ... \n";
for ( my $loop = 1; $loop <= 5; $loop++ ) {
print "Iteration: $loop\n";
## Perform some time consuming task here ##
sleep 1;
}
print "All Done!\n";