This is colloquial speech. Words are left out and understood from context.
"Forty cents a dozen" means "forty cents FOR a dozen." The word "for" is left out, because the meaning is clear without it.
You pay $0.40. You receive 12 of something..
"Per" is used in business. "Forty cents per dozen" means the same thing as "Forty cents for a dozen."
"Forty cents per" here means "forty cents per DOZEN." The buyer understands, because the seller was talking about dozens earlier.
The seller needs to say "per." If the conversation had been
"Well, how much for them?" "Forty cents." the buyer would not be sure what was meant and would need to ask
"Is that forty cents each, or forty cents per dozen?"
By adding "per" the seller makes it clear that he does NOT talking about "forty cents each."