in reply to replacing while keeping the position of the element in the file

I think what you want to do is split the first file into a hash of what each word is coded to:
my %sentence_codes = map { /(.*)_(.*)/ && ($1,$2) } split $codefile;
Then just do a global replace on the second file:
$sentence_file =~ s/(\w['-]\w?)|[?:;]/$&.'_'.($sentence_codes{$&} || ' +unknown')/eg;
I've no idea if this is what you wanted, but that's what I read into it. (This is all pseudo-code, really - you'd need to map the first file one line at a time)