Use the 'splice' function. The syntax is:
splice @array, $offset, $length, @list
- @array is the target array
- $offset is the starting array element to remove. The first element is 0. If '$offset' is negative it starts counting from the end of the array
- $length is the number of array elements to remove
- @list (optional) is a list of elements that will replace the element removed
In scalar context, 'splice' returns the last element removed. In list context returns the list of elements removed from the array.