$ perl -e ' use strict; use warnings; use autodie ":all"; my @hosts = qw{8.8.8.8 8.8.4.4}; my $command = join ";", map "ping -c3 ".$_, @hosts; my $result = qx{$command}; my $re = qr{(?s:^(\S+).+?(\S+)\s+ms\s*$)}; my $fmt = "%s min:%s avg:%s max:%s mdev:%s\n"; open my $mh, "<", \$result; { local $/ = "PING "; while (<$mh>) { chomp; next unless /$re/; printf $fmt, $1, split /\//, $2; } } ' 8.8.8.8 min:16.929 avg:17.290 max:17.585 mdev:0.272 8.8.4.4 min:15.392 avg:15.856 max:16.284 mdev:0.365