... while(<$fh>){ chomp; (my $ip = $_) =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; print $ip,$/; } ...