# You might already have this type of function available. # If not, it's needed for the next part: sub same_coord { my ($aref, $bref) = @_; my @acoord = @$aref; my @bcoord = @$bref; return 0 if ( scalar @acoord != scalar @bcoord ); foreach my $i ( 0..$#accord ) { return 0 if ( $acoord[$i] != $bcoord[$i] ); } return 1; } sub get_neighbors { my @coord = @_; my @n = ( [] ); foreach my $i ( 0..$#coord ) { @n = map { @left = @$_; map { [ @left, $_ ] } ( $coord[$i]-1..$coord[$i]+1) } @n; } @n = grep { !same_coord( \@coord, $_ ) } @n; return @n; }