use strict; #use warnings; #printing lots of undefs print "Enter your test strings:\n"; while () { chomp; print "\tTesting '$_':\n"; /^(?:(?:(\d+)\s*c\s*)|(?:(\d+)\s*w\s*)|(?:(\d+)\s*r\s*))+/i; print "Capturing \\d+ only: 1='$1', 2='$2', 3='$3'\n"; /^(?:(?:(\d+\s*c)\s*)|(?:(\d+\s*w)\s*)|(?:(\d+\s*r)\s*))+/i; print "Capturing \\d+ plus the letter: 1='$1', 2='$2', 3='$3'\n"; } __DATA__ 1c 2w 2c3w 1w1w 1w2r 2r1c