in reply to what is keys %$hash_ref [-1]

It's a syntax error. Is there more of the code?