$agent_value is declared two times.
The substitution should not be used with
my.
Just remove the second lexical declaration and the code works.
Also, I recommend to use
strict and
warnings.
'warnings' says:
"my" variable $agent_value masks earlier declaration in same scope at ...