Not an ad or anything, but Perlfect search might be useful by itself or as an example. It uses DBM files and binary packing of file numbers to save space.
I have no connection with them other than having clubbed their code with an optimization stick.