in reply to Doing a find/replace on the nth line

You've asked to substitue the nth occurance, and you've asked to substitute the occurance on the nth line. You've been provided with a solution the latter; what follows is solution to the former.

perl -pi -e "s/searchpattern/replacepattern/ if (/searchpattern/ && ++$match==3)" filename

hum, let's eliminate the redundancy:

perl -pi -e "substr($_,$-[0],$+[0]-$-[0], 'replacepattern') if (/searchpattern/ && ++$match==3)" filename