The data that you pass into hmac_sha512_hex
is interpreted as a string. You are passing it as a reference to a hash. You can verify this by printing the value of $data
before passing it into the function.
Your reference is just a unique identifier for your hash. Perl doesn't guarantee that you'll get the same hash reference for the same data in different runs of your program. You are therefore passing different values into hmac_sha512_hex
which will obviously give you different output.
If you want your output to be the same, then you need to find a way to pass the same string into the function each time. One simple approach might be to use the string that you get back from Data::Dumper's Dumper function.
Update: If you use Data::Dumper, then you'll need to set $Data::Dumper::Sortkeys
to a true value.