sub findfile { my $searchfile= shift; my $pathofbasedir= shift; opendir DIR,"pathofbasedir"; my @usefulfiles = grep{!/^\.{1,2}$/} readdir DIR; my @fileswithfullpath= map{$basepath."/".$_}@usefulfiles; closedir(DIR); foreach my $file (@fileswithfullpath) { if(-d $file) { findfile($searchfile,$file) } else { if( $file =~ /$searchfile/) { print "FIle exists at ",$file; exit(1); } } } }