I have the following string: Received: from mail.server.com (unknown [75.101.111.111]) Code (markup): and I find the IP address 75.101.111.111 using this regex: $sendingip =~ m/\[.*?((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\d])\]/is; Code (markup): How can I replace 75.101.111.111 with 127.0.0.1 and change the string to this: Received: from mail.server.com (unknown [127.0.0.1]) Code (markup): Thank you, Perl wizards! ~pgiddy
found the answer using s/// $string=~s/\[.*?((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\d])\]/127.0.0.1/; Code (markup):