use strict; use warnings; my @arr1 = qw{ this1 this2 this11 this21 this23 }; my @arr2 = qw{ h2this1 h3this2 h5this21 h6this23 h8this13 }; my @arr1Rx = map { [ $_, qr{$_\z} ] } @arr1; foreach my $e2 ( @arr2 ) { foreach my $e1 ( @arr1Rx ) { print qq{$e1->[ 0 ] belongs to $e2\n} if $e2 =~ $e1->[ 1 ]; } }