http://www.perlmonks.org?node_id=1013208


in reply to need urgent help for

  1. open file ("file1") to read;
  2. read a line;
  3. split it in 3 parts on white space;
  4. save results in an array;
    1. open the file name given by last array element ("pqr");
    2. write the array content to the file;
    3. close the file.
  5. repeat 2 until whole file is read;
  6. close the file.

Alternatively, if the last element of the lines being does not ever change, you would need to split the line only once and could open and close the file handle being written to outside of the loop, and read & write in consecutive statements.

Another variation could be is to save the file being read in a variable and write the value of that variable after everything has been read.