in reply to Re: Inserting an element into an array after a certain element
in thread Inserting an element into an array after a certain element

Ajusted to only do it once:

my $first = 1; @array = map { if ($first && $_ eq "c") { $first = 0; ($_, "x") } else { $_ } } @array;

hum, ugly. How about:

my $first = 1; @array = map { my @a = $_; push(@a, "x") if ($first && $_ eq "c"); $first ||= @a-1; @a } @array

Nope, still ugly. Well, you could always do:

foreach (0..$#array) { if ($array[$_] eq "c") { splice(@array, $_+1, 0, "x"); last; } }