@array = qw("this" "xxx" "is" not "xxx" and "xxx" "whatever"); #example array @m; $i=0; for(@array){ push(@m,$i)if $_=~/xxx/g; $i++; } print @m;