I once, many years ago, worked with a programmer who had a strict rule of not introducing any functions unless the block of code was used at least twice.
Every code base they were the main developer on had source files thousands of lines long with if-statements nested to the 9 levels of hell.
We worked mostly in Perl and Deplhi (Pascal). Reading old code was... interesting. It's wild when your Perl code is more readable than your Pascal.
I'm happy to say I don't work with them anymore.
So yeah, break things into functions and name your functions and variables sensibly. Your future self will thank you.