for my $x ( 1 .. 10 ) { my @keys; open my $file_handle, '<', "$filename$x" or die $!; while( my $line = <$file_handle> ) { if( $x == 1 ) { print $header, "\n"; @keys = split /\t/, $line; } else { # Do something with each line read in. } } }