All of the regexes listed above seem to have problems in one or more situations.
use strict;
use warnings;
while (<DATA>) {
chomp;
my ($last) = m|/([^/]+)/[^/]*$|;
print "$last\n";
}
__DATA__
/rootdir/sub1/sub2/sub3/sub4/
/rootdir/sub1/sub2/sub3/sub4/file
/rootdir/
/