sub ba2bi3 { my $ba = pack 'C*', (@_, (0) x (4 - ( @_ % 4 || 4 ) ) ); my $result = Math::BigInt->new(0); my $p = length($ba) - 4; do { $result <<= 32; #!4294967296; $result += unpack 'V', substr $ba, $p , 4; } while ($p-=4) >= 0; $result; } print ba2bi3( bigint_to_bytearray( Math::BigInt->new('1234567890' x 8) ) ); #### 11: +1234567890 <## 301: +1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 12345678901234567890 Benchmark: running best, clean, new, org , each for at least 10 CPU seconds ... s/iter org new clean best org 5.82 -- -77% -94% -94% new 1.31 344% -- -73% -73% clean 0.352 1555% 273% -- -1% best 0.349 1569% 276% 1% -- The results are the same #### C:\test>229290 Name "main::ba" used only once: possible typo at C:\test\229290.pl line 67. 301: +12345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890 12345678901234567890123456789012345678901234567890 Benchmark: running best, clean, demerphq, new, org , each for at least 10 CPU seconds Rate org new clean demerphq best org 0.173/s -- -78% -94% -94% -94% new 0.770/s 345% -- -73% -73% -73% clean 2.83/s 1533% 267% -- -1% -1% demerphq 2.86/s 1553% 272% 1% -- -0% best 2.86/s 1553% 272% 1% 0% -- The results are the same