use File::Find; open(INLIST, $ARGV[0]) or die "cannot open $ARGV[0]: $!\n"; my @all_paths = ; close INLIST; chomp @all_paths; foreach my $path(@all_paths) { if (-f $path && $path=~/\.dirlist$/){ open (LIST, $path) or do { print "cannot open $path: $!\n"; next; }; my @temp = ; chomp @temp; push @all_paths, @temp; close LIST; next; } elsif (-d $path) { find(\&scan_path_n_rename_file, $path); } }