As a debugging tool, you might want to print the values of $protein_matrix that you're pushing to @next_cell_arr within your while loop. You can also use Data::Dumper::Simple and print Dumper(@next_cell_arr); after your while loop finishes.
Comment on Re: Understanding variable scope in perl