I need to do something similar to this post (but with a twist). That is why I am asking.
unix shell: replace by dictionary
I have a dictionary(dict.txt). I
As long as your dictionary keys contain nothing but alphanumeric characters, this Perl will do what you need.
use strict;
use warnings;
open my $fh, '<', 'dict.txt' or die $!;
my %dict = map { chomp; split ' ', $_, 2 } <$fh>;
my $re = join '|', keys %dict;
open $fh, '<', 'user.txt' or die $!;
while (<$fh>) {
s/($re)/$dict{$1}/g;
print;
}