# I assume you are using 2 different pdls, not rows of the same pdl as you mentioned in your post # If it's just one pdl, 'dog' it my $value = pdl [ 1, 20, 60, 3, 900, 34, 93, 5, 12, 24, 16, 200 ]; my $mask = pdl [ 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 ]; # get the indices of $mask that are 0 my $indices = which $mask == 0; # detect lower and upper edges of sequential regions of indices my $lower_edges = $indices - 1 != $indices->rotate(1); my $upper_edges = $lower_edges->rotate(-1); # also: # my $upper_edges = $indices + 1 != $indices->rotate(-1) # now slice and dice up your piddles knowing the regions you want.