in reply to Persistent counter

use warnings; # or the -w switch
then you would have gotten an error telling you that
my $failedActivation = 0;
was only used once, (possible typo?) as you refer to it later mistakenly by
$failedActivations

Have a nice day
All decision is left to your taste