note
dvergin
As [3dan] notes, this question has been asked and answered many times. But just for fun, here's a quick (tested) solution that takes a different approach from that of [tcf22]. This leaves a hash (%counts) with all the results available for later processing. ([tcf22]'s approach could be adjusted to do that also.)
<code>
#!/usr/bin/perl -w
use strict;
my @array_1 = qw/A B/;
my @array_2 = qw/A B C D A D B A C/;
my %check_1 = map { $_ => 1 } @array_1;
my %counts;
map { $counts{$_}++ if $check_1{$_} } @array_2;
print "$_ : $counts{$_}\n" for keys %counts;
</code>
Which results in:<br />
<br />
A : 3<br />
B : 2<br />
<p align="center">
------------------------------------------------------------
<br>
<font size="-1">"<i>Perl is a mess
and that's good because the
<br />problem space is also a mess.</i>" - Larry Wall</font>
</p>
264346
264346