diff --git a/matlab/dynare.m b/matlab/dynare.m
index 2cb1bdee0a2d88d59a18bab0e92af77dbad76ff5..7b4f3c13eb42134df2009ad33a441fba9e2429cc 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -99,11 +99,7 @@ end
 
 % Testing if filename has more than one period (not allowed).
 dot_location=(strfind(fname,'.'));
-if length(dot_location)>1
-    error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions')
-end
-
-if dot_location==length(fname)
+if length(dot_location) > 1 || dot_location == length(fname)
     error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions')
 end