in reply to Search a string from beginning or end

Instead of basename, you could use fileparse, which is also part of the File::Basename module. For example: ($base,$path,$suffix) = fileparse($file, '\.[^.]*');