in reply to Update: problem with scalar

Another problem is that you open the output file like this:

open FILE2,'output.txt';

But with no mode specified, this defaults to reading (i.e., input mode), so each attempt to print to the file results in an error message like this:

print() on closed filehandle FILE2 at ...

As a general rule, you should prefer the three-argument form of open with the mode made explicit:

open FILE, '<', 'testFile.txt'; ... open FILE2, '>', 'output.txt';

And, as Laurent_R says, you should always check whether the open call succeeds. If you don’t want to write ... or die ... after each call, you can simply add the pragma:

use autodie;

at the head of your script. See autodie.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,