while (my $line = ) { my item = "UNKNOWN"; if ($line =~ /show port/) { $item = "port"; } if ($line =~ /show router interface/) { $item = "l3"; } if ($line =~ /Count:\s+(\d+)/) { $checks{$item}{$stage} = $1; } }