Under the assumption that you do not want rows with undefined values in your output (however they got there):
my @matrix_filtered = grep { defined( $_->[0] ) && $_->[0] =~ /$to_keep/ } @matrix;
You could simply silence the warning, but then you will get the bogus rows in your output if '' =~ /$to_keep/ is true.
In reply to Re: "Use of uninitialized value in pattern match (m//)" warning, doing a grep on 2D array
by Anonymous Monk
in thread "Use of uninitialized value in pattern match (m//)" warning, doing a grep on 2D array
by soblanc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |