in reply to treating the filesystem structure as hash of hashes

Use lc to store the keys to the hashes in lowercase. So that you have $filesystem{'/media/sdb2'}{'folder1'}{'directory'}{'file.txt'}.

Simply change

foreach my $entry (@content){ $entry = lc $entry
I threw out the 'sort', it has no use when you put things into a hash.

Your data structure could be much simpler by using the complete path with filename as key. So that $filesystem{'/media/sdb2'}{'folder1'}{'directory'}{'file.txt'} would be stored in something like $filesystem{'folder1\\directory\\file.txt'} instead.

EDIT: a few edits because I misread the problem