my $best_score = 9999; my $best_combo; my @list = qw(1 1 1 2 3 4 4 4 5 5 6 6 6 7 7 8 8 8); while (my $combo = get_combo(\@list)) { # hard to do well?? $score = get_score($combo); # easy if ($score < $best_score) { $best_score = $score; $best_combo = $combo; } } print $best_score.': '.Dumper($best_combo);