for(@array){ ($i)= grep { m/^#/ } $_; push @new, $i; }