For example, they want a chart on their web site using chart.js but don't know how to get and parse their data and know I can do that with Perl and some regex work. I'm not a pro at that but I know I can generally find out what I need to know to make it work for the task in hand.
I will certainly never use that regex again. They will probably use it for a very long time, or save a ton of time using it once.
So, yes, they would have to pay me to learn what I need to know to complete that task.
Another thing is if you want to qualify for certain freelance jobs. Let's say Qt is a thing you want to do professionally. Then it is very likely that you have to build up some knowledge and portfolio to get such a job. Then the freelancer pays for the time obviously.