in reply to How do I extract a file name from a path string

i loved amasidlover's answer, but i noticed that it needs one small revision to the regexp.

instead of:
m/^.+[\\|\/](.+?)$/
use:
m/^.*[\\|\/](.+?)$/

If you don't, then a path like '/file.txt' will show up as '/file.txt' instead of 'file.txt'.

not claiming i know 'why' either of them work, but they just do. Like, I can't figure out how, when you have only a filename without a path or slash, that the first bit ends up not failing the expression or ending up as part of the (captured) $1 expression.

Originally posted as a Categorized Answer.