in reply to Getting values for next array iteration when matching current

Anytime you need to look ahead, just loop by indexes instead of by element.
while (my $in = <IN>) { for my $i (0..$#ref) { if ($ref[$i] =~ m/$in/) { print OUT $ref[$i+1]; } } }