my @matrix; while () { chomp; # you forgot that - remove trailing newline char push(@matrix, [split]); }