foreach my $compName (keys %components) { foreach my $param (keys %{$components{$compName}}) { if ($param =~ /eth[0-9]$/) { # [ then loop again through the COMP keys, excluding the current key # ... does not seem nice ] } }