I've been trying to figure out what makes your code run so much faster, and I think I can more or less follow its logic but I'm not sure about one point. If you wanted to get from a starting point of 1 to an ending point of 7, you could do that with 1+1=2 2*2=4 2+1=3 4+3=7 With the algorithm, after you get one path with 1, 2, 4 and another path with 1, 2, 3 it looks like the first of those sets wouldn't allow you to add 4 in the next round because there is already a different path to reach 4, and the second of those sets wouldn't allow you to add 3 in the next round because there is already a different path to reach 3. (This is from the next if (exists($m->{$result})); line.) I'm wondering if it would have a way of discovering that path to 7? For the most part our algorithms seem to agree, but when I set the max size for both algorithms to 30, mine said you can go from 25 to 13 in 4 steps (from the matrix in my earlier post) while yours said that 25 to 13 took 6 steps (when I commented out the if ($start{$s}{$STEPS} == $start{$start_best}{$STEPS}) {and subsequent close bracket surrounding the print statement). A path with four steps is:25/25 = 1 25+1 = 26 1+1 = 2 26/2 = 13