sub parse_file ($) { #Do something with the file here. } sub traverse (@) { my @files = @_; local *DIRH; #If @files is empty, why bother? return unless @files; foreach my $file (@files) { #Skip unreadable files. next unless -r $file; if (-d $file) { #If it's a directory ... chomp(my $cwd = system('/bin/pwd')); #save current directory, ... chdir($file) || next; #change to the new directory, ... opendir(DIRH,$file) || next; #open it... traverse((readdir(DIRH)); #and recursively parse it. closedir(DIRH); #Close the directory. chdir($cwd); #Change directories back to where we were. } else { #If it's not a directory, then parse it. parse_file($file); #This is where the actual work is done. } } } traverse(@ARGV);