% perldoc perlsyn
>If any part of LIST is an array, "foreach" will get very confused if
>you add or remove elements within the loop body, for example with
>"splice". So don’t do that.

普通にgrep使え
普通に新規配列作れ