my $hosts = "C:/windows/system32/drivers/etc/hosts"; print "Line to add to hosts (x.x.x.x domain.com): "; my $line = ; print "IP to replace: "; chomp( my $ip = ); rename( $hosts, "$hosts.old" ); open IN, "$hosts.old" or die "Can't read $hosts.old $!\n"; open OUT, ">$hosts" or die "Can't write $hosts $!\n"; while (my $old = ) { print OUT $old unless $old =~ m/\Q$ip/; } print OUT $line; # add the new record close IN; close OUT;