use strict; use warnings; use Data::Dumper; my @things = ( 1, 2, 3, "and", 4, 5, "and", 7, 8, 9 ); my @bucket; my $counter = 0; foreach my $elt ( @things ) { if ($elt eq "and") { $counter++; } else { push @{ $bucket[$counter] }, $elt; } } print "counter = $counter\n", Dumper(\@bucket);