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; #### $VAR1 = [ 'keyB', 'keyA' ]; $VAR2 = [ [ '3', '5', '10', '14', '18' ], [ '2', '6', '8' ] ]; $VAR3 = [ 5, 3 ]; #### @tsub2 = keys %threads; @tlist2 = @threads{@tsub2}; @tsize2 = map { scalar @{$_} } @tlist2; print Dumper \@tsub2,\@tlist2,\@tsize2;