#!/usr/bin/env perl use strict; use warnings; my @number_names = qw{zero one two three four five six seven eight nine}; my $pattern = qr{ ( [0-9] ) }x; my @strings = ('8, 9, 5', '3-2-1-0', 'Testing: 1 2 3'); for my $string (@strings) { print "DIGITS: $string\n"; $string =~ s/$pattern/$number_names[$1]/g; print "NAMES: $string\n"; } #### DIGITS: 8, 9, 5 NAMES: eight, nine, five DIGITS: 3-2-1-0 NAMES: three-two-one-zero DIGITS: Testing: 1 2 3 NAMES: Testing: one two three