Part of the problem here may also be the printf "%d". I just tried it (without use integer) on a 32-bit system/perl*, and the printf simply outputs -1, while print $degeneracy outputs the correct value without problems.

(AFAICT (i.e. using ltrace), Perl comes with its own printf implementation, and doesn't call the one provided by the system's libc, so this should be system-independent.)