my $dir = "/htdocs/project1/docs/file.html"; my ($parent) = $dir =~ m#\A.*/([^/]+)/[^/]*\z#; print $parent, "\n";