Gene arrangement into operons varies between bacterial species. Genes in a given system can be on one operon in some organisms and on several operons in other organisms. Existing theories explain why genes that work together should be on the same operon, since this allows for advantageous lateral gene transfer and accurate stoichiometry. But what causes the frequent separation into multiple operons of co-regulated genes that act together in a pathway? Here we suggest that separation is due to benefits made possible by differential regulation of each operon. We present a simple mathematical model for the optimal distribution of genes into operons based on a balance of the cost of operons and the benefit of regulation that provides 'just-when-needed' temporal order. The analysis predicts that genes are arranged such that genes on the same operon do not skip functional steps in the pathway. This prediction is supported by genomic data from 137 bacterial genomes. Our work suggests that gene arrangement is not only the result of random historical drift, genome re-arrangement and gene transfer, but has elements that are solutions of an evolutionary optimization problem. Thus gene functional order may be inferred by analyzing the operon structure across different genomes.