\documentclass{article}
\usepackage{xepersian}
% classes 1-3 are used in unicode-letters.tex, so we'll put the Latin  letters in 4
\newcount\n
\n=`\A \loop \XeTeXcharclass \n=4 \ifnum\n<`\Z \advance\n by 1 \repeat
\n=`\a \loop \XeTeXcharclass \n=4 \ifnum\n<`\z \advance\n by 1 \repeat
% when we encounter class 4, we'll do \startlatin
\XeTeXinterchartoks 0 4 {\startlatin}
\XeTeXinterchartoks 255 4 {\startlatin}
% and when we encounter class 0, we'll do \finishlatin
\XeTeXinterchartoks 255 0 {\finishlatin}
\XeTeXinterchartoks 4 0 {\finishlatin}
\newif\iflatin
\newcommand{\startlatin}{\iflatin\else\bgroup\beginL\latinfont\latintrue\fi}
\newcommand{\finishlatin}{\iflatin\unskip\endL\egroup{ }\fi}
\XeTeXinterchartokenstate=1
\begin{document}
سلام دنیا
hello world
این یک آزمایش بود
\end{document}