#!/usr/bin/perl use strict; use warnings; my $CHR_NUM = $ARGV[0]; my $file_location = "/home/ALL.chr$CHR_NUM.phase1_release_v3.20101123.snps_indels_svs.genotypes.vcf.gz"; my @id_files; # you might find a better variable name for that array of arrays for my $x (1..75) { # $x is a poor name for a variable, perhaps $file_nr would be better my $file_in = "/home/raj/HAPLOTYPES_JAN_2015/PROG_1_Approach_2/C22-$x"; open my $FH, $file_in or die "Cannot open $file_in $!"; # if one fails, you might be happy to know which one of the 75 files while (my $line = <$FH>){ chomp $line; push @{$id_files[$x]}, $line; } close $FH; } #### 0 ARRAY(0x600500ae8) 0 empty slot # $x starts as 1, so no element for subscript 0 1 ARRAY(0x600500c68) 0 'line1 file 1' 1 'line2 file 1' 2 ' ... etc.) 2 ARRAY(0x600500b30) 0 'line 1 file 2' 2 ' ... etc. ... etc. 75 ARRAY(0x6005.....) 0 'line 1 file 75' 2 ' ... etc. #### print $id_files[$x][2];