#assume files a.txt and b.txt exist and are normal, readable files. use strict; use warnings; open(FILE_A,"<","a.txt") || die "Could not open file 'a.txt': $!\n"; open(FILE_B,"<","b.txt") || die "Could not open file 'b.txt': $!\n"; my @FH=(*FILE_A,*FILE_B); for(my $i=0;$i<2;$i++){ while(my $line=<$FH[$i]>){ print "line: $line\n"; } } exit(0); #### #...as before... for(my $i=0;$i<2;$i++){ my $fh=$FH[$i]; # <----** while(my $line=<$fh>){ #...as before...