#!perl -sw my $input = [[1, 3, 4, 2], [7, 5, 3, 6], [5, 4, 2, 4]]; my $SEP = " "; my $send; sub printarray { my $arr = shift; for my $t (@$arr) { for (@$t) { print "$_ "; } print "\n"; } } sub encode { my $arr = shift; join $SEP x 2, map { join $SEP, @$_ } @$arr; } sub decode { my $in = shift; [(map { [(split $SEP, $_)] } split($SEP x 2, $in))]; } printarray($input); print "\n" x 2; $send = encode($input); print $send . "\n" x 2; $input = decode($send); printarray($input);