d2 # matches the letter 'd' followed by the number '2' # not what you want d{2} # matches the letter 'd' at least and at most 2 times # this is what you want s/1//; # replaces the number '1' with nothing # not what you want s/$1// # does what you want