# ... for ($i = $#arry; $i >= 0; $i--) { next unless $arry[$i] == 5; splice @arry, $i, 1; # no need to adjust $i here, going backwards. }