in reply to Regex output incorrect

In your regex, the the dot matches any character, and in particular, it matches the slash before 2010. That's the first character that you don't want, so one way to get the correct output is to capture everything up to there:

use strict; use warnings; my $folder_path = "/aboutiso/corp_gov/bod/agendas/2010"; $folder_path =~ s#((/\w+)+)/\w+$#$1#; print "folderpath: $folder_path\n";
I replaced the dot with a slash since that's the first character I don't want.