# (untested) use Data::Diver qw[Dive DiveVal]; use Algorithm::Loops 'NestedLoops'; NestedLoops( [ ( [0..$dimension-1] ) x $depth ], sub { my @indices = @_; my $val = Dive( \@multi_dimensional_array, @indices ); ## do something with $val. say, push it to an array } );