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