in reply to Write to different file name

Here is my guess, but probably wrong, because your question is not very clear.
$text = "file1.txt"; open (DAT,">file2.txt"); print DAT "$text\n" or die $!;
Please ask your question in more detail, and you'll be helped sooner.

Courage, the Cowardly Dog