#!/usr/bin/perl -w use strict; my @sample=("3D6+","3D6","3D6+4","3D6+4x1000"); ##############################THE BIG, THE ONE my $rexp='^([1-9][0-9]*)[Dd]([1-9][0-9]*)(\+([1-9][0-9]*)(x([1-9][0-9]*))?)?$'; my ($dtime,$dface,$foo,$addfact,$bar,$mulfact); foreach (@sample) { if (/$rexp/) { map{$_=0 if !defined($_)}($dtime,$dface,$foo,$addfact,$bar)=($1,$2,$3,$4,$5); $mulfact=(!defined($6))?1:$6; print "$_ is $dtime dices with $dface faces plus $addfact all mult by $mulfact\n"; } }