in reply to Pattern Matching

The easiest way is File::Basename.

But maybe you want to show us what code you already wrote and how it fails for you?