my @matrix; while( <> ) { chomp; push @matrix, [ split /\s*,\s*/, $_ ]; } # Now @matrix is an array of array references.