@array = do { my @array2; foreach ( @array ) { push @array2, $_; push @array2, "new_element" if $_ eq 'remove'; } @array2; };