my %hash = ( "NETWORK1" => "A", "NETWORK2" => "B", "TYPE1" => "C", "TYPE2" => "D"); my @networks = @hash{ grep /^NETWORK/, sort keys %hash };