use strict; use warnings; use IO::Handle; # <-- Added this line for autoflush $| = 1; my $bsize = 512; my $ulimit = `ulimit -f`; chomp $ulimit; print "ulimit=$ulimit blocks (block size=$bsize)\n"; my $fname = 'f.tmp'; open my $fh, '>', $fname or die "error: open '$fname': $!"; $fh->autoflush(); # <-- Added this line to make print autoflush my $niter = 1000; my $size = 0; my $block = 'a' x $bsize; for my $i (0..$niter) { print "$i: $size bytes written\n" if $i % 100 == 0; print $fh $block or die "$i: error in print: $!"; $size += $bsize; # <-- Moved this line to after successful print } close $fh or die "error: close: $!";