use strict; use warnings; open(my $fh, '>:unix', "test.txt") or die "test.txt: $!"; foreach my $i (1..20) { print $fh "iteration $i\n"; sleep(5); } close($fh);