my @array = (undef) x $size[0]; $_ = [ map { [(0) x $size[2]] } (undef) x $size[1] ] for @array; #### $array[$foo][$bar][$baz] = $quux if $foo >= -$size[0] and $foo < $size[0] and $bar >= -$size[1] and $bar < $size[1] and $baz >= -$size[2] and $baz < $size[2];