use strict; use warnings; use feature 'say'; use Path::Iterator::Rule; my $dir = '1230046/public_html/software'; my $_numMissing = 0; my $_filesThere = 0; my $r = Path::Iterator::Rule->new->file->exists->and(sub { my $wanted = $_[0] =~ s!software/!!r; -e $wanted ? $_filesThere++ : $_numMissing++ && say "$wanted is missing"; })->all($dir); say " Found: $_filesThere"; say "Missing: $_numMissing"; __END__ #### ls -R 1230046 1230046: public_html 1230046/public_html: 42.txt 43.txt bar quux software 1230046/public_html/bar: 42.txt baz 1230046/public_html/bar/baz: 42.txt 43.txt 1230046/public_html/quux: 43.txt 1230046/public_html/software: 42.txt 43.txt bar foo quux 1230046/public_html/software/bar: 42.txt 43.txt baz 1230046/public_html/software/bar/baz: 42.txt 43.txt 1230046/public_html/software/foo: 42.txt 43.txt baz 1230046/public_html/software/foo/baz: 42.txt 43.txt 1230046/public_html/software/quux: 42.txt 43.txt #### $ perl 1230046.pl 1230046/public_html/foo/42.txt is missing 1230046/public_html/foo/43.txt is missing 1230046/public_html/quux/42.txt is missing 1230046/public_html/foo/baz/42.txt is missing 1230046/public_html/foo/baz/43.txt is missing Found: 6 Missing: 6