in reply to remove words with regex
XY problem, as usual.
Based on the example, what you actually want is File::Basename.
Yurp, or possibly Path::Tiny.
The cake is a lie. The cake is a lie. The cake is a lie.