my @arr; while (my ($x, $y, $beans) = read_grid_cell) { push @arr, [$x, $y, $beans]; } # Or the equivalent map statement, if you like.