The movie, which is shooting in New York, is about the obscenity trial sparked by Allen Ginsberg's famous poem. It co-stars James Franco, Mary-Louise Parker, David Strathairn, Jeff Daniels, Bob Balaban, Treat Williams and Alessandro Nivola.
TV's "Perry Mason" was based on Ehrlich's life, Variety.com noted.
Hamm is best known for his role on the AMC drama series "Mad Men."
Police: Sword-wielding man demanded free tacos
Campus cop fatally shoots Texas student during traffic stop