It's not clear to me what your problem is. Is your problem that you currently have just one $im, but want more? In that case, you should probably use an array. Or is your problem that you have to write to multiple files? In that case, instead of writing to STDOUT, open one or more files yourself (using the open function) and write to the filehandles using print.