#!/usr/bin/perl use strict; use warnings; my @first = qw(Can unlock secret); my @second = qw(you the code?); my @mixed = interleave_words( scalar(@first), @first, @second ); print "Result: @mixed\n"; sub interleave_words { my @results; my $count = shift; foreach my $index ( 0 .. $count-1 ) { my @merge_list = splice (@_, 0, 2); # my @merge_list1 = splice (@merge_list, 0, 2+1); print "Result: @merge_list\n"; } if (@_!=$count) { die "Second array not same size ($count) as the first\n"; } return @results; }