in reply to $- ??

It should be $_ like the others explained. Let's look at why it doesn't work with $_. (I don't see how it would work with $- any better.) You're missing parens in your first match. m// returns 1 or undef/() if you have no captures.

{ my @new; $_ = 'bla'; push @new, $_ =~ m/^bla/; print(@new, "\n"); # prints 1 } { my @new; $_ = 'bla'; push @new, $_ =~ m/^(bla)/; print(@new, "\n"); # prints bla }

$_ =~ is redundant and can simply be ommited. Also, s/...(.*)/...$1/ is the same as s/.../.../. The final product is:

while (<IN>) { push @new, m/^(\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+)/; print "\n$#num\n"; } while (<REPLACE>) { s/^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+/$new[$i++]/; print OUT $_; }