use strict; use warnings; #emulate reading from 1st file my %lookup = (); while () { chomp; my $key = (split /_/)[0]; $lookup{$key} = $_; } #emulate 2nd file my @input = ("I would like to learn this ! .", "OK ?"); foreach my $line (@input) { my @tokens = map {$lookup{$_} || 'unknown'} split /\s+/, $line; print "@tokens\n"; } 1; __DATA__ I_pron would_mod like_v to_to learn_v this_pron ._sent OK_ok ?_quest