Erbium-doped fiber amplifiers (EDFAs) have great importance in long-distance communication. It is required to have equal gain for all signals that are transferred and to avoid loss in the receiver of long-distance communication systems. However, temperature dependence changes the output spectrum of the designed gain-flattening systems. In this study, each erbium-doped fiber (EDF) length of a two-stage L-band EDFA has been optimized using a genetic algorithm method; because of the temperature dependence of EDFAs, there is no general rule. Thus, a simple, fast, dynamic, and highly accurate model has been developed and obtained for different EDF lengths that will fix gain along the L-band. The results have been shown to be very compatible with the previously obtained numerical values.