$s = 'abc 1 23 do 456 re 789 me 0123 456 2 23 456 789 0123 456'; push @results, ("This has " . length($1) . " digits: $1") while $s =~ /(\d+)/g; print "$_\n" for @results; # Prints: # This has 1 digits: 1 # This has 2 digits: 23 # This has 3 digits: 456 # This has 3 digits: 789, etc. #### $s = '1 23 456 789 0123 456 2 23 456 789 0123 456'; push @results, ("This looks like a word: $1") while $s =~ /((?:\b\d{1,2}\s+)+\b\d{3,})/g; print "$_\n" for @results; # Prints: # This looks like a word: 1 23 456 # This looks like a word: 2 23 456