my @copy; while (@$r) { push @copy, [ shift @$r, shift @$r ]; } $r = \@copy;