"tr/*SEARCHLIST*/*REPLACEMENTLIST*/cdsr" Transliterates all occurrences of the characters found in the search list with the corresponding character in the replacement list. It returns the number of characters replaced or deleted. If no string is specified via the "=~" or "!~" operator, the $_ string is transliterated. If the "/r" (non-destructive) option is present, a new copy of the string is made and its characters transliterated, and this copy is returned no matter whether it was modified or not: the original string is always left unchanged. The new copy is always a plain string, even if the input string is an object or a tied variable. Unless the "/r" option is used, the string specified with "=~" must be a scalar variable, an array element, a hash element, or an assignment to one of those; in other words, an lvalue. A character range may be specified with a hyphen, so "tr/A-J/0-9/" does the same replacement as "tr/ACEGIBDFHJ/0246813579/". For sed devotees, "y" is provided as a synonym for "tr". If the *SEARCHLIST* is delimited by bracketing quotes, the *REPLACEMENTLIST* has its own pair of quotes, which may or may not be bracketing quotes; for example, "tr[aeiouy][yuoiea]" or "tr(+\-*/)/ABCD/". Characters may be literals or any of the escape sequences accepted in double-quoted strings. But there is no interpolation, so "$" and "@" are treated as literals. A hyphen at the beginning or end, or preceded by a backslash is considered a literal. Escape sequence details are in the table near the beginning of this section. It is a bug in Perl v5.22 that something like tr/\N{U+20}-\N{U+7E}foobar// does not treat that range as fully Unicode. Note that "tr" does not do regular expression character classes such as "\d" or "\pL". The "tr" operator is not equivalent to the tr(1) utility. If you want to map strings between lower/upper cases, see "lc" in perlfunc and "uc" in perlfunc, and in general consider using the "s" operator if you need regular expressions. The "\U", "\u", "\L", and "\l" string-interpolation escapes on the right side of a substitution operator will perform correct case-mappings, but "tr[a-z][A-Z]" will not (except sometimes on legacy 7-bit data). Note also that the whole range idea is rather unportable between character sets--and even within character sets they may cause results you probably didn't expect. A sound principle is to use only ranges that begin from and end at either alphabets of equal case (a-e, A-E), or digits (0-4). Anything else is unsafe. If in doubt, spell out the character sets in full. Options: c Complement the SEARCHLIST. d Delete found but unreplaced characters. s Squash duplicate replaced characters. r Return the modified string and leave the original string untouched. If the "/c" modifier is specified, the *SEARCHLIST* character set is complemented. If the "/d" modifier is specified, any characters specified by *SEARCHLIST* not found in *REPLACEMENTLIST* are deleted. (Note that this is slightly more flexible than the behavior of some tr programs, which delete anything they find in the *SEARCHLIST*, period.) If the "/s" modifier is specified, sequences of characters that were transliterated to the same character are squashed down to a single instance of the character. If the "/d" modifier is used, the *REPLACEMENTLIST* is always interpreted exactly as specified. Otherwise, if the *REPLACEMENTLIST* is shorter than the *SEARCHLIST*, the final character is replicated till it is long enough. If the *REPLACEMENTLIST* is empty, the *SEARCHLIST* is replicated. This latter is useful for counting characters in a class or for squashing character sequences in a class. Examples: $ARGV[1] =~ tr/A-Z/a-z/; # canonicalize to lower case ASCII $cnt = tr/*/*/; # count the stars in $_ $cnt = $sky =~ tr/*/*/; # count the stars in $sky $cnt = tr/0-9//; # count the digits in $_ tr/a-zA-Z//s; # bookkeeper -> bokeper ($HOST = $host) =~ tr/a-z/A-Z/; $HOST = $host =~ tr/a-z/A-Z/r; # same thing $HOST = $host =~ tr/a-z/A-Z/r # chained with s///r =~ s/:/ -p/r; tr/a-zA-Z/ /cs; # change non-alphas to single space @stripped = map tr/a-zA-Z/ /csr, @original; # /r with map tr [\200-\377] [\000-\177]; # wickedly delete 8th bit If multiple transliterations are given for a character, only the first one is used: tr/AAA/XYZ/ will transliterate any A to X. Because the transliteration table is built at compile time, neither the *SEARCHLIST* nor the *REPLACEMENTLIST* are subjected to double quote interpolation. That means that if you want to use variables, you must use an "eval()": eval "tr/$oldlist/$newlist/"; die $@ if $@; eval "tr/$oldlist/$newlist/, 1" or die $@;