Win8 Strawberry 5.30.3.1 (64) Sat 09/26/2020 11:37:04 C:\@Work\Perl\monks >perl use strict; use warnings; my $kards; my $bad = 'AKQJT98765432KKKK'; my $card = 'K'; my $e_string = "$kards = $bad =~ tr/$card//"; # print "e_string: >$e_string< \n"; # for debug eval $e_string; print "1: Num of '$card' in $bad is == $kards \n"; my $kings = $bad =~ tr/K//; print "2: Num of '$card' in $bad is == $kings \n"; __END__ Use of uninitialized value $kards in concatenation (.) or string at - line 8. Use of uninitialized value $kards in concatenation (.) or string at - line 12. 1: Num of 'K' in AKQJT98765432KKKK is == 2: Num of 'K' in AKQJT98765432KKKK is == 5 #### Win8 Strawberry 5.30.3.1 (64) Sat 09/26/2020 12:14:28 C:\@Work\Perl\monks >perl use strict; use warnings; my $n_found; my $string = 'AKQJT98765432KKKK'; my $set = 'AQK'; # s/// probably fastest in practice. my $destroy = $string; # s/// alters its target $n_found = $destroy =~ s{ [\Q$set\E] }{}xmsg; print "s///: Num of '$set' in '$string' == $n_found \n"; # m// probably a bit slower, use of =()= a bit tricky. $n_found =()= $string =~ m{ [\Q$set\E] }xmsg; print "m//: Num of '$set' in '$string' == $n_found \n"; # tr/// is fastest, but needs expensive eval for arbitrary sets. $n_found = $string =~ tr/KAQ//; print "tr///: Num of 'KAQ' in '$string' == $n_found \n"; __END__ s///: Num of 'AQK' in 'AKQJT98765432KKKK' == 7 m//: Num of 'AQK' in 'AKQJT98765432KKKK' == 7 tr///: Num of 'KAQ' in 'AKQJT98765432KKKK' == 7