in reply to Optimizing hash lookups

Not sure if this affects your algorithm, but typically if you have a directory set up at /foo/ and someone requests /foo, the server will redirect the browser to /foo/, so your access logs will have a hit for each.

You should also use exists instead of defined for hash keys.

Your code also has a few errors.. Not sure if you just copied this by hand or if this is actual code. I'm going to assume the former, but I'll give you a list if it's the latter.