@numbers = ('25', '12', '32','56','45','21','65'); @needed = ('25','32','45','65'); #### e.g. get 25 12 32 and 45 21 65 #### for (my $i=0; $i<@numbers; $i++) { # psudocode # # if $numbers[$i] matches a value in @needed; # push @found, all the numbers until the next match for (my $k = 0; $k < @needed; $k++) { if ($numbers[$i] == $needed[$k]) { push @found, $numbers[$i]; # not sure how to carry on until the next match! } } } }