use Data::Dumper; $copy=1; #what you want? %threads=( keyA => [ 2, 6, 8 ], keyB => [ 3, 5, 10, 14, 18 ], ); $tnum=0; foreach $thread (keys %threads) { $tsub[$tnum] = $thread; $tlist[$tnum] = $threads{$thread} unless $copy; @{$tlist[$tnum]} = @{$threads{$thread}} if $copy; $tsize[$tnum] = @{$tlist[$tnum]}; $tnum++; } print Dumper \@tsub,\@tlist,\@tsize;