diff --git a/matlab/dynare.m b/matlab/dynare.m
index 5517846fb36c5e55e726dbe3b777d75bece055ba..5e66c9b733106a29c4220b4ffe9d1da354d9e918 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -112,10 +112,8 @@ if isempty(strfind(fname,'.'))
     fname = fname1;
 else
     % Check provided file extension.
-    if dot_location~=length(fname)-3 ... %if the file name has fewer than 4 characters and there is a period
-            || ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ...
-            && ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN')
-        error('DYNARE: argument must be a filename with .mod or .dyn extension and must not include any other periods')
+    if ~strcmpi(fname(dot_location+1:end), 'mod') && ~strcmpi(fname(dot_location+1:end), 'dyn')
+        error('DYNARE: argument must be a filename with .mod or .dyn extensions')
     end
     fnamelength = length(fname) - 4;
 end