in reply to using less structures

I agree with talexb, if you could make an example that is "runnable", this helps a lot. In the best case, I just copy and paste your code into my development editor and push the "go" button!

Please do not delete anything from your current post. If say you even had a completely new formulation, just say UPDATE and post the revised code as an addition. Sometimes I download some code and then maybe some hours elapse before I actually post my reply. If you have removed what I'm replying to, that creates confusion.

Ok, with limited understanding, I will post some general comments:

Sounds like you had working code, then a new situation showed up - the possibility of getting more detailed directory info via a text file (the "file" key) instead of just higher level directory info via the "data" key. You responded by testing for this new condition in a couple of different places. This among other things has resulted in: In the first case I use the array @roots_paths and in the second case I have to use two structures %paths and @roots_paths.

It appears to me that the goal is to create the @list_of_dirs array. In the "data" case, you have to do some searching to find the sub dirs and in the "file" case, you are going to believe what the file says about sub dirs without any searching.

If the goal indeed is to create the @list_of_dirs array, consider refactoring the code to decide what situation you are in and just get on with the job, perhaps:

my @list_of_dirs; # Create @list_of_dirs; if( defined($opt_href->{"data"}) ) { # We have to do some searching to find complete list of dirs @roots_paths = (split /,/, $opt_href->{"data"}); foreach $path (@root_paths) { find( sub { get_valid_dir( \@list_of_dirs) }, $path); } } else { # Directory info is in a file, just have to validate info is corre +ct blah...blah.. }
I don't know for sure, but perhaps some intermediate variable "weirdness" will go away if the focus is upon creating the list_of_dirs. Something to consider is making this procedure a sub: my @list_of_dirs = get_dirs(...). Also, comments and whitespace consume ZERO mips! Those lines can often be some of the most important "code" lines that you write. Perhaps, even: # example "data" key is "...".

You ignore what I probably would judge sufficient to cause a fatal error.
 open(my $fh, '<', "$file_path") or return 0; or
 next unless(isValidDir($fub_path));
In general when dealing with a file, I assume that the "file is right". If there is a problem with the file, the "right" answer is often to fix the corrupted file and run the program again. I do make a distinction between a file generated by a program and a file generated by a human. The possible scenarios are many - more than I can detail here.

I have a number of "micro comments" about specific lines. I don't think they are important now.

Additional comment: I am not sure why you would prefer the "data" key over the "file" key? What happens if both keys are in the hash?