in reply to accessing a part of a string

If you are manipulating filesystem paths, use the Path::Class::Dir module and its dir_list method.

If you are manipulating URIs, use the URI module and its path_segments method.

If it is neither, simply use a regular expression that captures everything up to the last /.

'some/very/varied_length/string' =~ m|(.*/)| # expression returns ('some/very/varied_length/')