# always start your scripts with these two lines... use strict; use warnings; # and declare your variables foreach my $i (2 .. 4) { my $filename = 'T' . $i . 'T.txt'; open (my $file, $filename) or die "Can't open '$filename': $!"; my @a = <$file>; print @a; close $file; }