my $hosts = "C:/windows/system32/drivers/etc/hosts"; print "Line to add to hosts (x.x.x.x domain.com): "; my $line = ; rename( $hosts, "$hosts.old" ); # effectively make backup open FILE, ">$hosts" or die "Can't write $hosts $!\n"; print FILE "127.0.0.1 localhost\n$line"; close FILE;