use IO::Handle; open my $Log, '>>', 'file.dat'; $Log->autoflush(1); while(<$serial>) { print { $Log } $_; }