remove anything after repeated string pattern found

HI,
Can anyone help me with a script.

i/p

calc 1 2 3 4 5 6 7 8
calc 4 5 6 calc 7 8 9

o/p

calc 1 2 3 4 5 6 7 8
calc 4 5 6

i.e remove anything after where two times the string calc is found.

thanks

perl -pe 's/(calc.*?)calc.*/$1/g' inputfile
$ sed 's/\(calc.*\) calc.*/\1/' input.txt
calc 1 2 3 4 5 6 7 8
calc 4 5 6
$ sed 's/ c.*//' input.txt
calc 1 2 3 4 5 6 7 8
calc 4 5 6