in reply to problem with sleep!

Add $|=1 before the loop, and then learn about $| and output buffering.

% perldoc -q unbuffer

the lowliest monk