See also Perl only prints complete lines? which is exactly the same problem.
In reply to Re: Optimization problem? by moritz in thread Optimization problem? by Anonymous Monk