It is probably simpler to just slurp the entire file into an array and replace the while(<>) with an iteration over the array (untested code follows):
my @data = <>;
my $backup=$commandfile.".bak";
foreach $com (keys %hashnew) {
$ARGV[0]="$backup";
$^I=".bak";
foreach (@data) {
if ($hashnew{$com} == "all") {
unless (/$hashnew{$com}/../\*\ Exit\ context\ \*/) {
s/$com//g;
}
}
if (/$hashnew{$com}/../\*\ Exit\ context\ \*/) {
s/$com//g;
}
print;
}
}
Of course if you actually explained to us what you want to do we might be able to come up with a better suggestion as it is not entirely clear from your code.
/J\ |