my %reasons; while (my($city, $info) = each %$switch_hash) { while(my ($date, $reason) = each %$info) { next unless $reason =~ /^(\d+):(.*)/ and $date ne 'CODE'; $info->{$date} = $1; $reasons{"$city:$date"} = $2; } }