The part of the telecoms platform I maintain and develop at work is written entirely in Perl. It does incredibly well in every involved aspect, and with a higher-performing and more compact codebase compared to what would've been the outcome with Python, but I'm wary of my eventual departure from the employer because of how hard it is to find Perl people these days. As much as I love Perl I cannot say it's a future-proof choice and an absolute benefit to my employer.
If you pay a million dollars a year in salary, you'll have all the perl engineers you want.
If you pay "market rate", you'll have some good engineers and some desperate engineers, with the ratio slowly trending in the negative direction over time.
Point is, that's definitely a solvable problem, but only if you watch out for hard-to-quantify externalities.
Anyway, if the salaries have to keep going up to keep high quality engineers, the economics of rewriting and/or deleting legacy code start being a lot more straightforward.