#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my @A = ("Red", "Green", "Yellow"); my @B = ("Yellow", "Black","Yellow","Red", "White", "Yellow"); for my $x (@A){ my @matches; for my $y (0 .. $#B){ push @matches, $y if $B[$y] eq $x; } say $#matches < 0 ? "$x is missing" : "$x at index " . join ', ', @matches; }