use strict; use warnings; use Data::Dumper; my $molec1 = "molec1"; my $molec2 = "molec2"; my $input1; my $input2; my $path = "/store/group/comparisons"; my @files; my $line; my @columns; my $nextUnless = 2; # nr of lines to skip my $CountLines = 0; # total nr of lines in all files for my $i (1..3) { push @files, "$path/File-${molec1}-cluster${i}.out"; } for my $j (1..2) { push @iles, "$path/File-${molec2}-cluster${j}.out"; } print "@files \n"; # for testing; are correct files printed? ## now split and print my @list; for my $file (@files) { open my $FH, "<", $file or die "Cannot open $file $!" while ($line = <$FH>) { $CountLines += 1; next unless $. > $nextUnless; chomp $line; $line =~ s/^\s+|\s+$//g; push @list, [split/\s+/, $line]; @columns = split /\s+/, $line; # this is most probably wrong, may be you need to push a reference, as you did in the previous line } close $FH; } print Dumper \@list; # check that the content of @list is what you expect # ...