if ( $elt ne "and" ) { push ( $elt, @{ $bucket[$counter] } ); } if ( $elt eq "and" ) { $counter++; } #### 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); #### counter = 2 $VAR1 = [ [ 1, 2, 3 ], [ 4, 5 ], [ 7, 8, 9 ] ]; #### use strict; use warnings; use Data::Dumper; my $things = 'this and that and another brigand and a bandicoot'; my @bucket = split /\band\b/, $things; print Dumper(\@bucket); #### $VAR1 = [ 'this ', ' that ', ' another brigand ', ' a bandicoot' ];