my $file = "/htdocs/project1/docs/file.html"; my $elif = reverse $file; my $slash = index($elif,'/'); my $index = length( $file ) - $slash; $index--; my $dir = substr($file,0, $index); print $dir;