in reply to No other way?

You should really use File::Spec for things like this. It's easy, the code is already written, and its cross-platform.
File::Spec->splitdir()