foreach $thread (keys %threads) { $tsub[$tnum] = $thread; $tlist[$tnum] = $threads{$thread}; $tsize[$tnum] = @{$tlist[$tnum]}; $tnum++; } print "\n\nThe Thread Arrays\n\n"; for ($i=0;$i<$tnum ;$i++) { print "\n$tsub[$i], size=$tsize[$i], @{$tlist[$i]}"; } #### # Define the arrays as lexical vars. # So you are sure they are not conflicting with other vars in the program my @tsub; my @tlist; foreach $thread (keys %threads) { # using push you don't need the counter push(@tsub, $thread); push(@tlist, $threads{$thread}); } print "\n\nThe Thread Arrays\n\n"; for ($i=0;$i<@tsub ;$i++) { # compute tsize only when you need it, another array is useless my $tsize=@{$tlist[$i]}; print "\n$tsub[$i], size=$tsize, @{$tlist[$i]}"; }