my $foo = 'thisisatest'; for(0 .. -2 + length $foo) { substr((my $bar = $foo), $_, 2, reverse substr $foo, $_, 2); print $bar, $/; }