sub recurse { my($path) = @_; print( "working in: $path\n" ); # append a trailing / if it's not there $path .= '/' if($path !~ /\/$/); # loop through the files contained in the directory for my $eachFile (glob($path . '*')) { # if the file is a directory if( -d $eachFile) { # pass the directory to the routine ( recursion ) recurse($eachFile); } else { handleFile( $eachFile ); } } }