You can use an OO approach. Create a subclass of
IO::Dir which returns only the files you want. This probably is slightly longer than what you already have, but it separates the special code from your application. (And it would be available for reuse)