$s = '1 23 456 789 01 23 456'; push @results, $1 while $s =~ /((?:\b\d{1,2} )+\b\d{3,})/g; print "Match: $_\n" for @results; # Prints: # Match: 1 23 456 # Match: 01 23 456