#!/usr/bin/perl use strict; use warnings; open PO, "netstat -na|" or die "Can't pipe open: $!\n"; my %count; while () { next unless /^udp/ or /^tcp/; my @fields = split; # split $_ on whitespace $count{$fields[3]}++; ## next jumps here } close PO; for my $ip (sort keys %count) { print "\t$count{$ip} $ip\n"; }