sub roll { my ($max) = @_; return 1 + int rand $max; } sub sum { my $sum = 0; $sum += $_ for @_; return $sum; } my @dice; ROLL: for (1..4) { push @dice, roll 6; pop @dice and redo ROLL if $dice[-1] == 1; } # Discard lowest @dice = sort { $a <=> $b } @dice; unshift @dice; my $sum = sum @dice;