The exsits operation is not the problem. What the error message says is that $cacheHOA{$sum} contains
a string, apparently a file name, and when you do
$#{$cacheHOA{$sum}} you are trying to use that string as an arrayref. You have not given enough
code to show us where you are setting$cacheHOA{$sum} to a string, removing the
arrayref that, presumably, was in there.