in reply to Finding a match between two paired arrays

Here's a small subroutine that'll test for a matched pair.

FWIW, using $a and $b as variable names in non-example code can get confusing pretty fast, especially if you're writing any sort routines.

use warnings; use strict; our @arr_1 = qw/ 1 1 2 1 1 2 2 1 2 /; our @arr_2 = qw/ ab aa aa ab ac ac ad ac ac /; my ( $input1, $input2 ) = ( 1, 'ab' ); my ( $input3, $input4 ) = ( 1, 'ad' ); print "test1: ", find_match ( $input1, $input2 ), "\n"; print "test2: ", find_match ( $input3, $input4 ), "\n"; #unless ( find_match ( search pair ) ) { do something } sub find_match { my ( $in1, $in2 ) = @_; return scalar grep { $in1 eq $arr_1[$_] && $in2 eq $arr_2[$_] } 0..scalar @a +rr_1 - 1; }