package File::MyFileType; sub open { my ($class, $filename ) = @_; ... $self->_initialize_headers; # initialize headers would write something like # Checksum: XXXXXXXXXXXXXX in the first line # reserving space for file's header } sub write { my ($self, $data) = @_; $self->_update_checksum($data); } sub close { $self->_update_headers; # Update header rewinds the file and replaces the # XXXXXXXXXX with the accumulated checksum ... } 1;