#! /usr/local/bin/perl use diagnostics; use warnings; use strict; use Games::Dice 'roll_array'; # this module rocks (well rolls anyway ;-) use List::Util qw(sum); my $rolls = 6; for my $roll (1 .. $rolls) { # how many sets of dice rolls determined by the value of $rolls my @rolls = roll_array '4d6'; # magic ;-) print "raw rolls: @rolls\n"; @rolls = sort @rolls; # sorted lowest to highest shift @rolls; # remove the lowest value by shifting it off print "top three rolls: @rolls\n"; my $sum = sum(@rolls); # List::Util's sum print "total: $sum\n"; }