open(DAT, '>', ...) || die(...); { my $old_sel = select(DAT); $| = 1; # Auto-flush. select($old_sel); } ... #### sub flush { my $h = select($_[0]); my $af=$|; $|=1; $|=$af; select($h); } flush(*DAT); #### my $dat = IO::File->new($filename, 'w') or die(...); $dat->autoflush(1); print $dat ...; # Auto-flushed. $dat->print(...); # Auto-flushed. $dat->autoflush(0); print $dat ...; # Not flushed. $dat->print(...); # Not flushed. $dat->flush(); # Flushed. $dat->printflush(...); # Flushed.