in reply to Re^2: matching substring in url
in thread matching substring in url

In that case:

echo "$XXX" | perl -ne '/\/(\w+)[^\/]*?$/ and print $1'