in reply to This may be more of a math question

Just in case...

Perhaps you misunderstand the ^ operator? That's the XOR operator, although many people mistakenly assume it's the exponent operator. Exponents are done with the ** operator. See perlop.

Update: Ah, slow typing will be the death of me someday...

buckaduck