in reply to reading and writing a CGI cookie in the same page

You've already gotten an answer to the question you posed, so I'll add a minor coding suggestion.

You can eliminate a conditional by writing

push @new_cookies, cookie_creator_sub() if <<some condition>>; ... $q->header(-cookie => [ @new_cookies ]);
If @new_cookies is empty, no cookies are added. This approach gives the flexibility of adding additonal cookies without having to modify existing code.