#!/usr/bin/perl use warnings; use strict; my %counts; open my $PARAM, '<', 'param' or die "param: $!"; while (<$PARAM>) { my ($count, $word) = split; $counts{$word} = $count; } open my $SENT, '<', 'sent' or die "sent: $!"; while (<$SENT>) { chomp; print; print " $counts{$_}" if exists $counts{$_}; print "\n"; }