#If you don't need the original string: $var =~ s|[^/]+/$||; #If you would like to leave $var unchanged: ($newVar) = $var=~ m|(.+/)[^/]+/$|;