use strict; use warnings; use Data::Dumper; my @array = ("create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove","create", "mount", "remove"); my $nset = 3; my $every = 10; my $newelement = "newelement"; my @newarray; while( @array ) { for( 1..$every ) { # for 10 times push @newarray, splice @array, 0, $nset; # push a set onto new array } push @newarray, $newelement; # add the new element } print Dumper \@newarray;