my $pos; for (0..$#array) { $pos=$_ and last if $array[$_] eq $wanted; } @array[$pos,-1]=@array[-1,$pos];