in reply to Search and replace from one list to another

One Liner (Because it is possible && fun) option:
perl -MPath::Tiny -pe 'BEGIN{m/_id = (\d+) id = (\S+)/ and $id{$1}=$2 + for path("contacts.txt")->lines} s/handle_id = (\d+)/$id{$1}/' messa +ges.txt

                Memory fault   --   brain fried