diff --git a/matlab/dynare.m b/matlab/dynare.m
index 2308ad8e3302c910e090d2d5958c721ecfcf44df..fae26232007027a5e5136f55419519898f5ea14b 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -297,17 +297,13 @@ if status
     error('Dynare: preprocessing failed')
 end
 
-if ~ isempty(find(abs(fname) == 46))
-    fname = fname(:,1:find(abs(fname) == 46)-1) ;
-end
-
 % We need to clear the driver (and only the driver, because the "clear all"
 % within the driver will clean the rest)
-clear(['+' fname '/driver'])
+clear(['+' fname(1:end-4) '/driver'])
 
 try
     cTic = tic;
-    evalin('base',[fname '.driver']);
+    evalin('base',[fname(1:end-4) '.driver']);
     cToc = toc(cTic);
     if nargout
         DynareInfo.time.compute = cToc;
@@ -315,7 +311,7 @@ try
 catch ME
     W = evalin('caller','whos');
     diary off
-    if ismember(fname,{W(:).name})
+    if ismember(fname(1:end-4),{W(:).name})
         error('Your workspace already contains a variable with the same name as the mod-file. You need to delete it or rename the mod-file.')
     else
         rethrow(ME)