use Game::Die::Dice; my $input = "1D4x10"; my ($pass_to_module, $mult) = split('x', $input); $mult = defined($mult) ? $mult : 1; my $dice = new Games::Die::Dice($pass_to_module); my $treasure -= $mult * $dice->roll();