my $line = 'client 127.0.0.1#47560: query: host.example.com IN AAAA'; (my $ipaddr) = (split/[\s#]/,$line)[1]; print "$ipaddr\n"; __END__ prints: 127.0.0.1