sed replace 2nd instance

Hello,

I want to replace 2nd instance of "foo" in a file use sed.

Any suggestions?

sed 's/foo/FOBAR/2' 

I believe that only replace 2nd instance in a line, but what if I want to replace 2nd instance in a file?

thank you for the suggestion