#!/usr/bin/perl use strict; my @matrix; while (<>) { chomp; # you forgot that - remove trailing newline char push(@matrix, [split]); }