I thought that as well, but when I tried to refactor to the more efficient form (passing all directories at once), I noticed that the code in the &wanted sub needs to know the "root" directory name: $file =~ s{^\Q$incl_dir/\E}{ };. Passing all the dirs at once removes the ability to see $incl_dir.