#!/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: $!"; while () { # look for the line like: PING www.google.com (10.160.83.59): 56 data bytes next unless /PING\s+(\S+)\s+\(([\d.]+)\)/; print "host: $1\n"; print "IP: $2\n"; }