use Regexp::Common qw/net/; my $ip_regexp = qr($RE{net {IPv4}); while() { if (/($ip_regexp)/) { my $ip_address = $1; print "$ip_address\n"; } } __DATA__ client 127.0.0.1#47560: query: host.example.com IN AAAA +