in reply to URL Regex Matching, again

Where is $string coming from?

You need anchor the regex to the end of the string to check if the last part of the string is bar optionally followed by a slash.

$string =~ m|bar/?$/;
Your regex effectively matches any string containing bar not followed by a dot.