#!/usr/bin/perl -w use strict; # Set up the arrays my @array1 = qw(a b c d); my @array2 = qw(b a e f); # Create the hash, based on array1 my %hash; foreach (@array1) {$hash{$_} = 1;} # Loop through array2 looking for matches foreach (@array2) { if ($hash{$_}) {print $_, "\n"} }