Yes, it is possible.
Classic UI
- Open the "Find and Replace" dialog box either by choosing in the top
menu
Edit > Find > Replace
or using the dedicated shortcut
Ctrl+R ( ⌘ R on Mac).
- Enter your search and replace terms.
- Select some area in your code.
- Press the dedicated button to only search within a selection:

Now if you press "Replace All", only the items found inside your selection will be replaced.
New UI
In the new UI of IntelliJ IDEA the "Search In Selection" option is in another place (kudos to @Chris for pointing this out):
- Open the "Find and Replace" dialog box either by choosing in the top
menu
Edit > Find > Replace
or using the dedicated shortcut
Ctrl+R ( ⌘ R on Mac).
- Enter your search and replace terms.
- Select some area in your code.
- Open "Filter Search Results" dialog by pressing the dedicated button and click on the first option "Search In Selection".

Now if you press "Replace All", only the items found inside your selection will be replaced.
NOTE
You can also open the "Filter Search Results" dialog using the shortcut (Ctrl+Alt+F on Windows/Linux, ⌃⌥F on macOS), but in this case it is important that the cursor is inside the "Search" field.
In similar way you can perform just a search (i.e. without replace) inside a selected area in your files. Look inside the Edit > Find
menu for more interesting options.
Here is the official IntelliJ IDEA documentation that covers this topic: Find in selection.