for (){ chomp; # each item of the array is placed in $_ for the scope of the for unless (open (D,$_)){ # no need to wrap the variable in quotes print STDERR "$!:$_\n"; # In case the failure to read one file isn't critical next; # Skips all the other commands in the loop and goes to the next iteration. } my $newrecord=$addthis.join('',); close(D); open (D,">$_") || die "Could not write to: $! \n"; print "$_\n"; print D $newrecord; close (D) }