Another way to handle this issue is the approach described in the documentation for
CGI:
Note, that just like all the other form elements, the
value of a hidden field is "sticky". If you want to
replace a hidden field with some other values after the
script has been called once you'll have to do it manually:
$query->param('hidden_name','new','values','here');
I was surprised by this behavior myself when I first encountered it, but now that I'm aware of it it's very useful. In fact, the stickiness of form elements is one of my favorite features of CGI.pm, because making your form elements sticky is a big pain when you're writing the HTML yourself.