my $string = "/opt/pmg/ptt/book1_test"; my @path = split /\//,$string; delete @path[-1]; my $path = join '/',@path;