#! /usr/bin/perl use strict; use warnings; my @array = qw (one two three four five); my %hash = (one => 'Extra information for one', two => 'Extra information for two'); foreach my $id (@array) { if (exists $hash{$id}) { print "ID: $id has extra info: $hash{$id}\n"; } else { print "ID: $id has no extra info\n"; } }