Use a non-greedy modifier to make the +
match as few characters as possible instead of as many as possible:
$pattern = str_replace(':any', '(.+?)', $pattern);
^
You probably also want to add delimiters round your regular expression and anchor it to the start of the string:
$pattern = '#^/foo/:any/#';