#! /usr/bin/perl use strict; use warnings; my $x=1; my @arr= qw(foo cho roh foo kho foo moo foo); foreach(@arr){print $x++ if (/foo/)}