foreach $file (@filesforeach) { print "$file\n"; open(my $fh, "<", "$filenames_to_putback") or warn "$!\n"; while (my $row = <$fh>) { chomp $row; print "$row\n"; my @line = $file; for (@line) { if ($_ =~ /$row/) { chomp $_; # push @output, "found $_ that matched redo $file $row
"; move($_,$row) or warn "shit went wrong yo! $!\n"; } } } } # print "@output\n";