in reply to Re^2: search and replace
in thread search and replace
...all words that are seperated by space...
Ah... something you didn't mention in your OP.
In this case, you could do:
while (my $line = <INFILE>) { $line =~ s/(\S+)/$dict{$1} || $1/eg; print $line; }
In case zero is a valid index, too, you'd need
$line =~ s/(\S+)/defined $dict{$1} ? $dict{$1} : $1/eg;
Or, if you're using Perl 5.10, you could write instead
$line =~ s|(\S+)|$dict{$1} // $1|eg;
|
|---|