I am looking for an expression that gives the determinant of a matrix of the form

\begin{bmatrix} A & B & 0 & \dots & 0 & C \\ B & A & B & & 0 & 0 \\ 0 & B & A & \ddots & 0 & \vdots \\ 0 & & & \ddots & A & B \\ C & 0 & \dots & \dots & B & A \\ \end{bmatrix}

Just to clarify. The above matrix is a block tridiagonal matrix with "extra" block entries in the "corners" of the matrix. All block entries are of the same size. They are all square matrices of the same size.

My first port of call was to recursively apply the block formula given in the following link under the heading "Block Matrices".

https://en.wikipedia.org/wiki/Determinant

The expression gets quite messy. I was wondering if there was a paper or well known formula among mathematicians which would make easy work of such a task.

Each of the blocks $A,B,C$ are tridiagonal, toeplitz matrices which are invertable.

EDIT: attempting to implement the suggested solution given by Federico

I can write the above matrix as $$\mathcal{A} = \bar{\mathcal{A}} + UWV^T \in \mathbb{R}^{ml \times ml},$$ where $$U = [e_l \otimes\mathbb{I}_m,e_1 \otimes\mathbb{I}_m], W = diag(C,C), V = [e_1 \otimes\mathbb{I}_m,e_l \otimes\mathbb{I}_m]$$

and $$ \bar{\mathcal{A}} = \begin{bmatrix} A & B & & & & \\ B & A & B & & & \\ & B & A & \ddots & & \\ & & & \ddots & A & B \\ & & & & B & A \\ \end{bmatrix} $$

This allows me to say

$$\det\left(\bar{\mathcal{A}} + {UWV}^T\right) = \det (W^{-1} + V^T\bar{\mathcal{A}}^{-1}U)\det{W}\det \bar{\mathcal{A}}$$

The problem for me now is to somehow find an expression for the determinant of $\bar{\mathcal{A}}$ and the determinant of $W^{-1} + V^T\bar{\mathcal{A}}^{-1}U$.