in reply to $- ??

From perldoc perlvar:

$-
The number of lines left on the page of the currently selected output channel. Used with formats. (Mnemonic: lines_on_page - lines_printed.)

Punctuation variables are reserved for special purposes in Perl. Also, your second while loop is populating $_, not $-. So if you want the contents of <REPLACE> to be passed through that second substitution operator, you should bind $_ to it, not $-.

See also perldoc perlvar:

$_
The default input and pattern-searching space.

It has a special purpose. You used it correctly in the first while statement, but incorrectly in the second while.


Dave