in reply to Strange behaviour of tr function in case the set1 is supplied by a variable

likbez:

Feature, per the tr docs 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.

So if you want to use a string to specify the values in a tr statement, you'll probably have to do it via a string eval:

$ cat foo.pl use strict; use warnings; my $str1 = 'abcde'; my $str2 = 'eda'; my $diff1 = 0; eval "\$diff1=\$str1=~tr/$str2//"; print "diff1: $diff1\n"; $ perl foo.pl diff1: 3

...roboticus

When your only tool is a hammer, all problems look like your thumb.