in reply to (OT) should i limit number of files in a directory

I've done exactly what you are looking to do (several times).

Say your filename is 45624a44b89793087e9ef4d076018adb. Under /var/media (or whatever) make a folder like 4/5/6 and place 45624a44b89793087e9ef4d076018adb under that.

You end up with lots of folders.

Even better, make a folder named 45/62/4a and place your file in that. URI-to-Disk resolution is a snap.

my $ROOT_PATH = '/var/media/'; my $folder = $ROOT_PATH . join '/', $r->uri =~ m/^(..)(..)(..)/; # Folder is '/var/media/45/62/4a'

Taken further, you end up with 256^3 folders. That should be plenty (16.7 Million different folders in which to place your files!).