XY problem, as usual.
Based on the example, what you actually want is File::Basename.
In reply to Re: remove words with regex by kikuchiyo in thread remove words with regex by frank1