in reply to Optimization problem?
See also Perl only prints complete lines? which is exactly the same problem.