no strict; no warnings; my @things = ( 1, 2, 3, "and", 4, 5); my @bucket; my $counter = 0; foreach my $elt ( @things ) { if ( $elt ne "and" ) { push ( $elt, @{ $bucket[$counter] } ); } if ( $elt eq "and" ) { $counter++; } }