#!/usr/bin/perl open(InFile, "test.dat") || die; # open test.dat for reading open(OutFile, ">test1.dat") || die; # open or create to write while($line = ) { print $line; print OutFile $line; } close(OutFile); unlink("test.dat"); # delete