#!/usr/bin/perl -w use strict; my @ray = qw(one two three); my @two = qw(two next four); foreach my $x (@ray) { foreach my $y (@two) { print $x if ($x eq $y); } } #### if ($ID=~ m/one.txt two.txt three.txt/)