I don't understand your exact question. Does the code you show above fail?
If so, what does that have to do with credentials needing to be renewed every hour?
Get your code working without consideration of expired credentials. Then add that consideration later.
Perl redo could be and probably is appropriate, but I am not able to judge here.