in reply to Finding the index of a specific element in an array.

Iterate over the array ( foreach ) and compare

http://perldoc.perl.org/perlintro.html#for

#!/usr/bin/perl -- use strict; use warnings; use Data::Dumper; my @array = ( 2,4,7,5,8); my( @index7s ) = grep { 7 == $array[$_] } 0 .. $#array; print Dumper( \@array, \@index7s, [ @array[@index7s] ] ); __END__ $VAR1 = [ 2, 4, 7, 5, 8 ]; $VAR2 = [ 2 ]; $VAR3 = [ 7 ];