in reply to Error hash declaration

$hashofstates->($key) = $val;

FWIW, this statement attempts to de-reference  $hashofstates as a subroutine reference, invoking it and passing  $key to it as an argument, and to assign  $val to an lvalue exposed (if that's the right terminology) by the subroutine. All of this is possible in another Perl code-world, but as others have written, with the OPed code it's na'gonna happen.