diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc
index e9bce2212a4bf330533fcb151243eb9476314452..3e70440f720c8aa0cb15275d3d093ba6f1033bd9 100644
--- a/preprocessor/ModFile.cc
+++ b/preprocessor/ModFile.cc
@@ -442,7 +442,13 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool console,
               << "%           from model file (.mod)" << endl << endl;
 
   if (clear_all)
-    mOutputFile << "clear all" << endl;
+    {
+      mOutputFile << "if exist('OCTAVE_VERSION')" << endl
+		  << "  clear -all" << endl
+		  << "else" << endl 
+		  << "  clear all" << endl
+		  << "end" << endl;
+    }
 
   mOutputFile << "tic;" << endl
               << "global M_ oo_ options_ ys0_ ex0_" << endl