#!/bin/env perl use strict; use warnings; my @day_of_year = (4257,4257,4258,4259); # If @day_of_year only contains the days then there is no reason for matching for my $day_of_year (@day_of_year) { print "looking for things in $day_of_year folder /home/myfiles/day_of_year/$day_of_year/*/desired_file.txt\n"; # there may be multiple directories containing desired_file.txt my @desired_paths = glob('/home/myfiles/day_of_year/'.$day_of_year.'/*/desired_file.txt'); for my $info_desired_filepath (@desired_paths) { print "$info_desired_filepath \t\t is the file name \n\n"; ; open (my $info_FH, '<', $info_desired_filepath) or die "cannot open $info_desired_filepath..........\n\n"; print "found a file!!!!!!\n"; chomp(my @lines = <$info_FH>); close($info_FH); print "lines:\n"; print "$_\n" for @lines; # yep, we actually read the data } } __DATA__ Directory structure: myfiles/ day_of_year/ |-- 4257 | |-- a | | `-- desired_file.txt | |-- b | | `-- desired_file.txt | `-- c | `-- desired_file.txt |-- 4258 | |-- a | | `-- desired_file.txt | `-- c | `-- desired_file.txt `-- 4259 `-- c `-- desired_file.txt Output: skimming for the day of year number: 4257 looking for things in 4257 folder /home/myfiles/day_of_year/4257/*/desired_file.txt /home/myfiles/day_of_year/4257/a/desired_file.txt is the file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/b/desired_file.txt is the file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/c/desired_file.txt is the file name found a file!!!!!! lines: data bogus data skimming for the day of year number: 4257 looking for things in 4257 folder /home/myfiles/day_of_year/4257/*/desired_file.txt /home/myfiles/day_of_year/4257/a/desired_file.txt is the file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/b/desired_file.txt is the file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/c/desired_file.txt is the file name found a file!!!!!! lines: data bogus data skimming for the day of year number: 4258 looking for things in 4258 folder /home/myfiles/day_of_year/4258/*/desired_file.txt /home/myfiles/day_of_year/4258/a/desired_file.txt is the file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4258/c/desired_file.txt is the file name found a file!!!!!! lines: data bogus data skimming for the day of year number: 4259 looking for things in 4259 folder /home/myfiles/day_of_year/4259/*/desired_file.txt /home/myfiles/day_of_year/4259/c/desired_file.txt is the file name found a file!!!!!! lines: data