Ummmm...."Caution, Will Robinson!"
Perhaps your employer's procedure makes pay periods equivalent to the intervals between paydays... in which case, some paydays are for a longer pay period than others.
BUT
that just bends your mind and leads to complications beyond what you're trying to calculate.
All you really need to do -- based on the assertions in your OP -- is count months till you retire and multiply by two...and should you wish to use perl to do the arithmetic, you already have pointers to how to do it.
$anecdote ne $data ... and, rememember, check Ln42!