($wanted) = $string =~ m{ ( [^.]+ ) # save the non-. sequence to $1 \. # . [^./]+ # the final non-. non-/ sequence (?: / | $) # / or the end of the string }x;