s/href\s*=\s*/href=/ig; s,(?$1,g; You might try to think of something besides '\S*' also, in case the user puts in a period after the href, or puts it between parenthesis or ???. #### # Now its starting to get ugly! $str =~ s#((?i:$1!#eg;