use strict; use threads; use threads::shared; use Math::BigInt; use Data::Dump qw[ pp ]; use feature qw(say); my @numbers = ( 1 .. 10 ); my %result : shared; my @threads = map { threads->create( \&process, $_ ); } @numbers; $_->join for @threads; for my $key ( sort{ $a <=> $b } keys %result ) { say "$key : $result{ $key }"; } sub process { my $number = shift; my $factorial = factorial($number); lock %result; $result{$number} = $factorial->bstr; ### Extract the value from the object } sub factorial { my $number = shift; Math::BigInt->bfac($number); } #### C:\test>junk 1 : 1 2 : 2 3 : 6 4 : 24 5 : 120 6 : 720 7 : 5040 8 : 40320 9 : 362880 10 : 3628800