The
DB_File module provides tied hash access to BTREE data files, which make it very convenient to search for all keys that fall within a certain range. The documentation doesn't have an example of this, so here's one.
# Input: %btree is already tied to a $DB_BTREE file
# $first and $last define the range to search for
# It's assumed that the btree uses the default sort order
my $db = tied %btree;
my $key = $first;
my $value;
for (my $status = $db->seq($key, $value, R_CURSOR);
$status == 0 && $key le $last;
$status = $db->seq($key, $value, R_NEXT))
{
print "$key = $value\n";
}