use File::Find; find(\&wanted, '/clear/pp_00/ngbb'); sub wanted { next unless m|\.txt\z|is; if ($File::Find::name =~ m|/clear/pp_00/ngbb/([^/\\]+?)[/\\].*|) { print "the someName dir is $1\n"; } }