Perfect infinitives (have + past participle) can be used after modal verbs could, might, ought, should, would and needn’t to refer to unreal situations.
- I could have married her if I wanted to. (I didn’t marry her.)
- That was dangerous – he could have killed somebody. (He didn’t kill anybody.)
- You should have written – I was getting worried. (The person did not write.)
- She needn’t have invited them. (She invited them.)
- You were stupid to try climbing up there. You might have killed yourself. (The person didn’t kill himself.)
- If she hadn’t been so bad-tempered, I might have married her. (I didn’t marry her.)
- I ought to have phoned him this morning, but I forgot.
The structure modal verb + perfect infinitive does not always refer to an unreal situation. It can also be used to talk about possibility.
- She could/should/ought to/may/might/will have arrived by now.