in reply to How can I delete an element in a foreach cycle?

Generally it is considered a bad idea to delete or add elements to an array your are looping over. Unless you are very careful, you might either skip elements or fall into an infinite loop.

That being said, if you do not mind adding a temporary variable, this is another solution:

use strict; use warnings; my @array = qw /aap noot mies wim zus jet teun vuur gijs lam kees bok +weide does hok duif schapen/; my @temp_array; for (@array) { push @temp_array, $_ unless /a/; } @array = @temp_array; { local $, = '|'; print @array; }
Or at the cost cost of some added complexity, using slices and grep and map (how perlish can you get?):
use strict; use warnings; my @array = qw /aap noot mies wim zus jet teun vuur gijs lam kees bok +weide does hok duif schapen/; my $counter = -1; @array = @array[grep {$_} map {$counter++; /a/ ? undef : $counter;} @a +rray]; { local $, = '|'; print @array; }
the output of both is:
noot|mies|wim|zus|jet|teun|vuur|gijs|kees|bok|weide|does|hok|duif
Update: added another solution.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James