in reply to How to replace in one regexp

my $path = $1 if $target =~ m!^([^?]*?/)?([^/\?]*)(\?(.*))?$!;