Example:
$a = "abcd";
$b = "defg";
I need to find a way to sort $a and $b, toss out "abc" and "efg", to make $c = "d".
s/[$a]//gi;
or
s/[$a]/[$b]/gi;
I know that isn't the code you are looking for, but that is the starting approach I'd use. The range option is excellent for things like balanced text.
This statement leads me to believe that I don't understand the problem. I've used quite a few programming languages, and while they almost all have some kind of string search feature (like pos() to locate the position of a substring in a larger string) I've run into very few intersection routines.
What you are looking for is basically an intersection of two character sets, no? So if one string is "PUNCH JOKERS" and the other string is "PERL HACKER" then it finds all characters found in both strings, namely "PERHCKR" How are duplicate characters handled?
What is this about sorting? You mean sort the characters of the string, so that "EBACD" becomes "ABCDE"?
If this is what you want, it's not so hard, but this is certainly nothing that any programming language that I've ever heard of has "built-in."