%db = ( year => { month => { day => { foo => 1, bar => 1, baz => 1, and so on..., } } } ); if year, month, day I want 'n' keys from $db{year}{month}{day} if year, month I want 'n' latest keys from the days from $db{year}{month} if year I want 'n' latest keys from the days from $db{year} else no date defined I want 'n' latest keys from %db