in reply to Write to different file name

Well, the contents of your new file will be "file1.txt\n". Probably not what you wanted. I'm going to assume that a) you're doing some meaningful processing with the records in file1.txt, and want to put the contents in another file and b) that you don't want to clobber your original file. Let's see if this cuts it for you:
$text = "file1.txt"; $output = $text; while (-f $output){ $output .= ".new" } open(DAT,"$text") or die "Couldn't open $text for read: $!"; open(OUT,">$output") or die "Couldn't open $output for write: $!"; #your code goes here #stuff like while(<DAT>) #and print OUT $stuff_to_print;
What this does is check for the existance of the file before it tries to open it for write (which truncates the file, btw). If the file exists, it appends a ".new" to the end of the file name, and checks for existance again. When it succeeds, you know that you've got a filename that you can safely open without truncating. Of course, this method does have its flaws. For instance, what if you have two versions of the script running on the same file at the same time? Oh well, you've got something to go on at least...;)

thor