use strict; use warnings; use Fcntl qw( SEEK_SET ); use IO::Handle qw( ); my $qfn = 'test_eagi.tmp'; open(my $fh, '+>', $qfn) or die("Can't create \"$qfn\": $!\n"); $fh->autoflush(1); ( my $pos = tell($fh) ) >= 0 or die("tell: $!\n"); $fh->write('abcde') or die("write: $!\n"); seek($fh, $pos, SEEK_SET) or die("seek: $!\n"); my $buf = ''; while (!$fh->eof) { $fh->read($buf, 4096, length($buf)) or die("read: $!\n"); } print "$buf\n";