#!/usr/bin/perl use strict; use warnings; my $count = 1; my $interval = 5; my $pkt_size = 128; my $timeout = 5; my $phost = 'www.google.com'; open CMD, "ping -c $count -i $interval -s $pkt_size -w $timeout $phost |" or die "Can't open ping: $!"; my $host; my $ip; while () { # look for the line like: PING www.google.com (10.160.83.59): 56 data bytes next unless /PING\s+(\S+)\s+\(([\d.]+)\)/; $host = $1; $ip = $2; } print "host: $host has IP: $ip\n";