This is probably more overhead than you want, but using DBI with DBD::DBM (comes with DBI but you need to add SQL::Statement for richer SQL) you can treat your database as an, um, database, and use the LIKE operator to match the records you want with SQL. DBD::DBM can work with DB_File or with BerkeleyDb.