my @array; # I would use a better name if I knew the array's contents for my $file (@ARGV) { open my $FH, "<", $file or die "cannot open $file $!" while (<$FH>) { chomp and push @array, $_ and last if $. == 4; } } print "@array\n";