# Count question marks that are not in (escapable) quotes sub CountParam { my ($statement) = @_; return scalar grep $1 eq '?', $statement =~ /( \? # Question mark | "(?:\\.|[^\\"]+)*" # String in \-escapable "" | '(?:\\.|[^\\']+)*' # String in \-escapable '' | [^?"']+ # Anything else )/sgx; }