use warnings; use strict; use File::Copy; copy 'file.txt', 'file2.txt' or die $!; rename 'file2.txt', 'file.txt' or die $!;