use IO::Handle; open(my $fh, '>', $fn) or die; print $fh 'foo!'; $fh->flush(); # From IO::Handle