my @grid; foreach my $rec (@records) { $grid[$rec->{x}][$rec->{y}] = $rec; }