#!/usr/bin/perl $string = "My IP is 10.0.0.2"; if($string =~/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/{ $ip = $string; } print "$ip\n";