def __getitem__(self, key):
    if key in self:
        return super(PerlLikeDict, self).__getitem__(key)
for k in self:
    if type(k) == self.pattern_type:
        if k.match(key):
            return self[k]
raise KeyError('key %r not found' % (key,))
How can I read Perl data structures from Python?