Let's say you have an array of fruit that contains apple, banana, orange, and grape.
my @fruits = qw(apple banana orange grapes);
Each element in the array has a unique index number.
Splice can be used to add or remove any element in an array.
Thus, the following would remove orange from the array.
splice (@fruits, 2, 1);
Often, the elements in an array are dynamic, thus you usually wouldn't want to hard code in the index number. Instead, the following can be used to get the index number of a specific element in the array.
my ($index) = grep { $fruits[$_] eq "orange" } (0 .. @fruits-1);
$index = defined $index ? $index : -1;
In this example, $index will contain a value of 2, thus the following can be done to remove orange.
splice (@fruits, $index, 1);