Let's define
- $S$ as the multiset,
- and $m_k$ as the multiplicity of the element $k$ of the multiset
$
S=(m_1,m_2,...,m_n)
$.
We want all the unique permutations of length $l$ of the multiset.
For the formula, we have to find all the combinations $C=(x_1,x_2,...,x_n)$ where $0 \leq x_k \leq m_k$ such that
$$
\sum_{k=1}^n x_k=l
$$
What we need is actually the product of the factorials of the elements of that combination:
$$
P(C)=\prod_{k=1}^n x_k!
$$
Now let's define the number of combinations as J. So to answer your question, the number of permutation is
$$
\sum_{j=1}^J \frac{l!}{P(Cj)}
$$
or the closed-form expression, where $\binom{n}{k_1,k_2,...,k_m}=\frac{n!}{k_1!k_2!...k_m!}$ is a multinomial coefficient
$$
\sum_{x_1+x_2+...+x_n=l} \binom{l}{x_1,x_2,...,x_n}
$$
Let's try this formula with this example: the multiset is $S=(3,2,1)$ and $l=4$. All the combinations are
$$
C=((1,2,1),(2,1,1),(2,2,0),(3,0,1),(3,1,0))
$$
so the number of permutation is
$$
\frac{4!}{1!2!1!}+\frac{4!}{2!1!1!}+\frac{4!}{2!2!0!}+\frac{4!}{3!0!1!}+\frac{4!}{3!1!0!}=\frac{24}{2}+\frac{24}{2}+\frac{24}{4}+\frac{24}{6}+\frac{24}{6}=38
$$
I'm going to use this example to explain my formula above. We want a permutation of length $l$, so it's like having 4 slots to fill up with what we have. In this case we have our multiset $S=(3,2,1)$. We start with the first element $m_1=3$. How many of $m_1$ we can use, remembering that we have $l$ free slots and that after $m_1$ we have $m_2+m_3=3$ to use? The answer is
$$
MAX(0,l-m_2-m_3) \leq x_1 \leq MIN(l,m_1)
$$
We can't use less or more, or we won't reach $l$ at the end. So $x_1=(1,2,3)$. Let's start with $x_1=1$. What is the number of combinations with $4$ free slots and $1$ to use? This is the binomial coefficient
$$
\binom{l}{x_1}=\binom{4}{1}
$$
What I'm going to do, is to repeat what I did until I completely fill all the slots. Now we have $l-x_1=3$ free slots and $m_2$ to use. Of $m_2$ I can use no less than $MAX(0,l-x_1-m_3)$, and no more than $MIN(l-x_1,m_2)$. So $x_2=(2)$ as it's the only choice. What is the number of combinations with 3 free slots and 2 to use? Like before, it's
$$
\binom{l-x_1}{x_2}=\binom{3}{2}
$$
Combined with $x_1=1$ it becomes
$$
\binom{l}{x_1}\binom{l-x_1}{x_2}=\binom{4}{1}\binom{3}{2}
$$
Now we have $l-x_1-x_2=1$ free slots, and $m_3$ to use. One slot can be filled in only one way, so $x_3=1$ and the combinations are
$$
\binom{l-x_1-x_2}{x_3}=\binom{1}{1}
$$
Combined with $x_1=1$ and $x_2=2$ it becomes
$$
\binom{l}{x_1}\binom{l-x_1}{x_2}\binom{l-x_1-x_2}{x_3}=\binom{4}{1}\binom{3}{2}\binom{1}{1}
$$
We can clearly see a pattern here, so we can try to get a nicer formula from that
$$
\binom{l}{x_1}\binom{l-x_1}{x_2}\binom{l-x_1-x_2}{x_3}=\frac{l!}{x_1!(l-x_1)!}\frac{(l-x_1)!}{x_2!(l-x_1-x_2)!}\frac{(l-x_1-x_2)!}{x_3!(l-x_1-x_2-x_3)!}
$$
We can simplify that and get
$$
\frac{l!}{x_1!x_2!x_3!(l-x_1-x_2-x_3)!}
$$
Since we know that $x_1+x_2+x_3=l$ we can simplify again and get
$$
\frac{l!}{x_1!x_2!x_3!(l-x_1-x_2-x_3)!}=\frac{l!}{x_1!x_2!x_3!0!}=\frac{l!}{x_1!x_2!x_3!}
$$
$$
\frac{l!}{x_1!x_2!x_3!}=\frac{4!}{1!2!1!}
$$
Now let's get back where we were. Since we filled up all the slots, we have to go back. Since $x_1=(1)$ and $x_2=(2)$, we have to get back to $x_1=(1,2,3)$ and pick the second, so $x_1=2$. $x_1=2$ implies $x_2=(1,2)$. Since there is more than 1 way to choose $x_2$, we can write it this way
$$
\binom{4}{2}\left[\binom{2}{1}+\binom{2}{2}\right]
$$
If we continue with $x_2=1$, we get $x_3=1$. And if we continue with $x_2=2$, we get $x_3=0$, and get
$$
\binom{4}{2}\left[\binom{2}{1}\binom{1}{1}+\binom{2}{2}\binom{0}{0}\right]=\binom{4}{2}\binom{2}{1}\binom{1}{1}+\binom{4}{2}\binom{2}{2}\binom{0}{0}=\frac{4!}{2!1!1!}+\frac{4!}{2!2!0!}
$$
Let's go back the last time to $x_1$ and pick up the last, so $x_1=3$. $x_1=3$ implies $x_2=(0,1)$, so
$$
\binom{4}{3}\left[\binom{1}{0}+\binom{1}{1}\right]
$$
If we continue with $x_2=0$, we get $x_3=1$. And if we continue with $x_2=1$, we get $x_3=0$ and get
$$
\binom{4}{3}\left[\binom{1}{0}\binom{1}{1}+\binom{1}{1}\binom{0}{0}\right]=\binom{4}{3}\binom{1}{0}\binom{1}{1}+\binom{4}{3}\binom{1}{1}\binom{0}{0}=\frac{4!}{3!0!1!}+\frac{4!}{3!1!0!}
$$
If we sum up all the results, we get the same formula as before.