sub interleave { my $y; while (@{ $_[0] } or @{ $_[1] }) { push @$y, shift @{ $_[0] } if @{ $_[0] }; push @$y, shift @{ $_[1] } if @{ $_[1] }; } return $y; }