Hard to say, as I can't really tell what your program is doing from top to bottom. It feels like maybe you're making a Perl equivalent to fuser or lsof. It may be, for example, faster overall to process on the fly versus parsing a bunch of things into a structure first.