What you need to do is called "shell scripting" or "shell programming". An introduction for scripting with the C shell (the one we AFNI-oids prefer) is here:
http://www-cs.canisius.edu/ONLINESTUFF/UNIX/shellprogramming.html
For your particular problem as posed, one solution involves creating and using shell variables, in a loop.
For example
set flist = ( `cat subject.list.txt` )
foreach sub ( $flist )
cd $sub
3dROIstats -1DRformat -quiet -mask maskROI.nii stats.nii > ../${sub}.ROI.1D
cd ..
end
Here, the first shell variable set is the array "flist" which contains the contents of the file "subject.list.txt" -- one string per entry in the array. This would be a file something like this:
FTX
FGY
FZN
FLQ
et cetera
where the code name for each subject is on a separate line.
For each subject, the script above assumes there is a directory with that name, and in that directory a dataset named "maskROI.nii" and one named "stats.nii".
The "foreach" command tells the shell to execute each of the commands, up to the "end", setting the shell variable "sub" to each of the entries in "flist" in turn. The "$" character is used to substitute the value of a shell variable onto the command line. Thus "cd $sub" will change directory into FTX the first time through the loop, to FGY the second time, and so on. Then the 3dROIstats command is executed in that directory, putting its output into the top level directory with a filename incorporating the subject identifier. Then the script changes directory back up one level and continues through the foreach loop until done.
You will have to understand this, and then adapt the script to the filenames and filename system that you actually use. Doing this requires using the general concepts of programming languages: variables, arrays, loops, variable setting, and variable usage.
If you don't know anything about programming at all, in any language, you will have a hard time. In which case, try the tutorial link above, and try to find help locally -- we won't be able to teach you programming remotely.