if(defined($opt_href->{"data"})) { @roots_paths = (split /,/, $opt_href->{"data"}); } else { my $file_path = $opt_href->{"file"}; open(my $fh, '<', "$file_path") or return 0; while (my $row = <$fh>) { chomp($row); if ($row =~ /(.*),(.*)/) { my ($main,$sub) = ($1,$2); my $fub_path = $main."/".$sub; next unless(isValidDir($fub_path)); push(@{$paths{$main}},$fub_path); push(@roots_paths,$main); } } close ($fh); } foreach my $main (sort(uniq(@roots_paths))) { if(defined($opt_href->{"data"})) { find( sub { get_valid_dir( \@list_of_dirs, $_ ) }, $root_path); } else { @list_of_dirs = @{$paths{$main}}; } # More same code here... }