my @m2; ## Input the matrix text file: print "\n\n Please type the filename(.txt) i.e. d1.txt: "; chomp( my $filename = ); open my $fh, '<', $filename or die "can't open file $!"; while (<$fh>) { push @m2, [ split /,/, $_ ]; } close $fh or die "can't close file: $!";