use strict; use warnings; #number of items to pack my $iter = 1000000; my $string; my $startAlloc = 0; my $preAllocSize = $startAlloc; Time (); $$string = ''; #now lets create the data block... for my $count (1 .. $iter) { if ($preAllocSize && length ($$string) >= $preAllocSize) { $preAllocSize = length ($$string) * 2; my $newStr = 1 x $preAllocSize; $newStr = $$string; $string = \$newStr; } $$string .= 'x' x 20; } Time (); print "Finished with start alloc: $startAlloc\n"; print "Final string length: ", length ($$string); sub Time { my ($user, $system, $cuser, $csystem) = times; print "$user,$system\n"; }