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