my %occurrences; for my $index (0 .. $#log) { if ($log[$index] =~ /^$FAILURE_SEARCH /) { $occurrences{ 1 + $index } = $log[$index]; } } return \%occurrences