my %map = ( ... ); $map{$_} = $_ for 0..9; my $numeric = join '', map $map{$_}, split //, uc($word); say $numeric;