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