#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Lingua::EN::Numbers qw{ num2en }; my $text = 'abc No. 347 xyz'; $text =~ s/No\. \K(\d+)/join "", "\\", map num2en($_), split m{}, $1/ge; print $text; # abc No. \threefourseven xyz