perl -i.bak -pe '$_="# $_" if(/^\$foo =/../^\$bar =/)' myscript.pl