use strict; use warnings; use Test::More tests => 3; my $filename = 'abstract-345.tex'; my $have = <<'EOT'; foo Here: \zerozerozero bar No. 345 baz EOT my $want = <<'EOT'; foo Here: \threefourfive bar No. 345 baz EOT my @digits = qw/zero one two three four five six seven eight nine/; my ($arabic) = $filename =~ /-([0-9]{3})\.tex/; (my $eng = $arabic) =~ s/([0-9])/$digits[$1]/g; $have =~ s/\\zerozerozero/\\$eng/; is $arabic, '345', 'Digits extracted'; is $eng, 'threefourfive', 'Converted to English'; is $have, $want, 'Replaced in text';