foreach $row(@nine) { foreach $column(@nine) { s/\d//; push(@matrix[$row][$column], $&); } }