The
Auto Erase option for the Pencil tool lets you paint the background
color over areas containing the foreground color.
Specify foreground and background colors.
Select the Pencil tool .
Select Auto Erase in the options bar.
Drag over the image.
If the center of the cursor is over the foreground color
when you begin dragging, the area is erased to the background color.
If the center of the cursor is over an area that doesn’t contain
the foreground color when you begin dragging, the area is painted
with the foreground color.