in reply to What is the best solution to swap input data?

I think that GrandFather's regular expression solution is the best for you but you ask what other solutions we have. davido has come up with an improved substr solution. Here's a way with split, splice and join.

use strict; use warnings; my $str = q{12345678}; print qq{$str\n}; $str = revByGroup($str); print qq{$str\n}; sub revByGroup { my $str = shift; my @chars = split m{}, $str; for (my $idx = 0; $idx < $#chars; $idx += 2) { splice @chars, $idx, 0, splice @chars, $idx + 1, 1; } return join q{}, @chars; }

and the output is

12345678 21436587

It copes with an odd numer of characters, leaving the last odd character at the end of the string. I hope this is of interest.

Cheers,

JohnGG