Versions of BerkeleyDB >= 3.0 have table and record level locks builtin. I have just started looking into them my self but you may want to check out
Apache::Session::BerkeleyDB and specifically
Apache::Session::Lock::BerkeleyDB and of course
BerkeleyDB.
The perl documentation for BerkeleyDB is lacking so you will probably have to have a look at the C API at
http://www.sleepycat.com.
perrin has a great article on perl.com that mentions some of the issues of using BerkeleyDB locking
here
-Lee
"To be civilized is to deny one's nature."