while $filename1 () { # removing trailing newline on $filename1: chomp $filename1; ... }