(let ((str "hogehoge,") (regexp ",$") (newstr ""))
  (cond
   ((eq emacs-major-version 21)
    (replace-regexp-in-string regexp newstr str))
   ((eq emacs-major-version 20)
    (progn (string-match regexp str) (replace-match newstr nil nil str)))
   ((eq emacs-major-version 19)
    (progn (require 'dired) (dired-replace-in-string regexp newstr str)))))