#!/usr/bin/perl use strict; use warnings; my %hash = ("One","1","Two","2","Three","3","Four","4"); my @lines = ("One", "Two", "Three"); my %count; foreach my $element (@lines) { $count{$element}++; } foreach my $i (sort {$hash{$a} <=> $hash{$b}} keys %hash) { if (exists $count{$i}) { print "$i,$hash{$i},Hit\n"; } else { print "$i,$hash{$i},Miss\n"; } } __END__ One,1,Hit Two,2,Hit Three,3,Hit Four,4,Miss