I think your more succinct version will have a problem with the first key. This is because $_ going into the map is going to be 0 thus prev => $keys[0 - 1] will result in prev => 10. At the other end, I think that next => $keys[$#keys + 1] will do the right thing as pointing off the end of the array should result in undef.