my $directory_path = undef; my @directory_path_file_list = undef; opendir DIR, $directory_path or die "Cannot open directory $directory_path"; @directory_path_file_list = readdir DIR; closedir DIR; #### my $text_file = undef; my @text_file_names = undef; $text_file = "text_file_with_names.txt"; open (my $fh, '<', $text_file) or die("Can't open input file \"$text_file\": $!\n"); while (my $line = <$fh>) { chomp $line; my @strings = $line =~ m/=(\s+\S+.txt)/x; foreach my $s (@strings) { @text_file_names = $1; } }