use strict; use warnings; $_ = '1,2,3,4,5'; print /(,?\d)+/; #### ,5 #### use strict; use warnings; my $str = '12/22/2005 20 Notice of Agenda of Matters Scheduled for Hearing (related document(s)2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, [17], 18, 19) Filed by Fubar, Inc.. Hearing scheduled for 4/11/2013 at 11:30 AM'; my ($series) = $str =~ m/\(Related document\(s\)([\]\[\d, ]+)\)/i; my @matches = split /,\s*/, $series; s/\[|\]//g for @matches; print "dollar amp is $&\n"; print "found " . scalar(@matches) . " matches.\n"; foreach (@matches) { print " $_\n"; }