You might try using
DBD::DBM which comes in recent versions of
DBI. It should work directly on your SDBM files (or other DBM files with or without MLDBM) and provide DBI/SQL access to them for greater ease of maintainability. If you go this route, I'd be interested to hear how it benchmarks against other methods you've tried.