I have a for loop with an if statement that looks like this:
   for (my $i=0; $i < $size; $i++) {
       if ($array[$i] =~ m/_(B|P|BC|PM)/) {
           #Remove from @array
           splice(@array, $i, 1);
           next;
       }
       #Get rid of numbers at the end
       $array[$i] =~ s/_[0-9]+//;
   }
I am getting an error saying that says "Use of uninitialized value within @array in pattern match...." on the line with the if statement.
When I remove the alternation from the regex on that line, the error goes away. If I comment out the whole if statement, the regex under the comment "#Get rid of numbers at the end" does not produce any errors.
I've printed out all values of @array and everything looks fine. I've tried no parentheses and brackets instead of the parentheses in the expression with no change. Any ideas what could be causing this?
 
     
    