in reply to character flipping

I really don't see any big improvements that could be made in that code. I did some benchmarking and I was able to get a small improvement for really large strings (at the expense of a small performance degredation for short strings) by computing the string length only once. i.e.
my $len=length($my_astr); $c1 = substr($my_astr, $p1 = int rand($len), 1); $c2 = substr($my_astr, $p2 = int rand($len), 1);

I was able to get another small performance boost by doing away with the temp variables $c1 and $c2. However, this code should be viewed with suspicion because it would really misbehave if you were moving more than 1 character blocks and the blocks happened to overlap.

$p1 = int rand(length($my_astr)); $p2 = int rand(length($my_astr)); substr($my_astr, $p1, 1, substr($my_astr, $p2, 1)); substr($my_astr, $p2, 1, substr($my_astr, $p1, 1));

When you say "flipping more than 2 characters at a time" do you mean "flipping 2 blocks of more than 1 character each" at a time or "flipping more than 2 blocks of 1 character each"?

flipping 2 blocks of more than 1 character at a time - would require either a check to prevent the blocks overlapping or special code to handle overlapping blocks properly (depending on how you define properly).

flipping more than 2 blocks of 1 character each - implementation of this depends on how you define flipping. If you pick A, B, C, and D to flip do you exchange A with B, B with A, C with D and D with A or do you replace A with B, B with C, C with D, and D with A?