GDBM - GNU DBM file library - is a nice library if you need to store a hash into a file in Perl (or in C). This is how to use it in Perl:
use GDBM_File;
tie %hash, 'GDBM_File', $filename, &GDBM_WRCREAT, 0640;
# ...
untie %hash;
The tie command associates a hash with the GDBM file, untie command disassociates it. As a result, hash values are stored to the gdbm file.
There's one thing to note: in Perl, the strings used as gdbm keys aren't null-terminated; in C, they are. You need to be careful in that case.