use strict; use warnings; use IO::File; my $fh = IO::File->new; $fh->open("counterfile", O_CREAT|O_RDWR|O_BINARY) or die $!; my $i; if( read($fh, my $buffer, 4)) { $i = unpack "N", $buffer; } else{ $i = 0; } $i++; $fh->truncate(0); $fh->seek(0,0); $fh->print( pack "N", $i ); $fh->close; print $i;