Assignment array with dependent on variable location

Hello,
this is my first question and i"m just learning the language right now.

assume that i have in the program:
bit [7:0] data [16]
bit [15:0] str

I tried to make something like this, with the purpose of masking the data according to the str bits:

bit [127:0] mask_data

foreach (str[n]) begin

if(str[n] == 0)
mask_data[8n + 7 -: 8 ] = 8’b00000000
else
mask_data[8
n + 7 -: 8] = data[n]
end

but the compilation cant be success because of the left side of the , which is not constant, and its a function of n.

do you have an idea what should i do in this situation, and how can i assign the data_mask with dependent on a variable?
thanks a lot
Yotam

In reply to yotamcr1:

It would help to show the actual code you are running and the error message. Please read this article on asking better questions.