use File::Find::Rule; foreach my $path ( @project_paths ) { my $rule = File::Find::Rule->file->name('*.xml')->start( $path ); if ( my $xml_file = $rule->match ) { print "The first XML file under dir '$path' is '$xml_file'\n"; } else { print "No XML files found under dir '$path'\n"; } }