use strict; use warnings; my @array_a = (10, 22, 34, 21, 20, 12, 32, 31, 91, 20); my @array_b = (10, 22, 34, 21, 20, 12, 32, 31, 91, 20, 11, 32, 44, 51, 10, 22, 82, 71, 61, 54); my @array_c = (14, 25, 64, 71, 80); my @new_a = (); my @new_b = (); my @new_c = (); my @sizes = (10, 20, 5); #sizes of array obtained elsewhere my @where_to = ('a', 'b', 'c'); foreach my $move_to (@where_to) { my $size = shift @sizes; my @moving = (); for (1 .. $size) { my $index = int rand @where_to; my $element = $where_to[$index]; push @moving, $element; } print "@moving\n"; foreach my $moving (@moving) { # my $moved = shift @array_$move_to; #I am not sure how to do this # push @new_$moving, $moved; #Again now sure how to do this #But even lacking the correct bit of code here, you can see, # where I am going with this. } }