Get all numbers
#!/usr/bin/perl use warnings; my $text = "3 A, 2 B, and 0 C"; $text =~ s/\b(\d+)\b/$1 > 0?$1 > 1?$1 > 2? "Several":"A pair of":"One":"No"/ge; print $text, "\n";