use v5.24; use strict; use warnings; # bad output { print "A: sleeping for 5s ..."; sleep 5; print "woke up\n"; } # cryptic solution { print "B: sleeping for 5s ..."; local $| = 1; sleep 5; print "woke up\n"; } # just to show that $| was localised { print "C: sleeping for 5s ..."; sleep 5; print "woke up\n"; } # still cryptic, but nicer solution { print "D: sleeping for 5s ..."; select()->flush(); sleep 5; print "woke up\n"; }