= a.txt = c.txt = b.txt = e.txt #### use warnings; use strict; my $directory_path = '.'; opendir my $dir, $directory_path or die "Cannot open directory $directory_path"; # create a hash with the files in the dir # (makes lookup faster later on) my %directory_path_file_list = map { $_ => 1 } readdir $dir; closedir $dir; my $text_file = "text_file_with_names.txt"; open (my $fh, '<', $text_file) or die("Can't open input file \"$text_file\": $!\n"); # define a new array for the files listed in the file, # extract the names, and push each filename onto the new # array my @files_in_file; while (my $line = <$fh>) { if ($line =~ /=\s+(\w+\.txt)/){ push @files_in_file, $1; } } # loop over the files found in the file, then check to see # if each one exists in the hash we created earlier. # you can perform your actions inside of the 'if' statement for (@files_in_file){ if (defined $directory_path_file_list{$_}){ print "$_ file exists on disk\n"; } else { print "$_ file doesn't seem to exist\n"; } }