use strict; use warnings; use IO::Socket::PortState qw(check_ports); my %porthash = ( ... ); check_ports($host,$timeout,\%porthash); for my $proto (keys %porthash) { for(keys %{ $porthash{$proto} }) { print "$proto $_ is not open ($porthash{$proto}->{$_}->{name}) if !$porthash{$proto}->{$_}->{open}; } }