#!/usr/bin/perl -w use strict; my @array = (2,4,7,5,8); # grep would return indicies of all 7's # here, just the first one is all we keep track of my ($first_seven) = grep{$array[$_] == 7}(0..@array-1); print $first_seven; # prints 2