#!/usr/bin/perl use strict; use warnings; use autodie; my @files = qw( 1.txt 2.txt 3.txt ); my @matrix; for my $file ( @files ) { open my $fh, '<', $file; push @matrix, [ map $_+0, <$fh> ]; } for my $i ( 0 .. $#matrix ) { my $row = $matrix[$i]; print "$i: @$row\n"; }