open my $LOG, '<', $logfile or die $!; my %occurrences; while (my $line = <$LOG>) { if ($line =~ /^$FAILURE_SEARCH /) { chomp $line; $occurrences{$.} = $line; } } return \%occurrences #### my %occurrences; for my $index (0 .. $#log) { if ($log[$index] =~ /^$FAILURE_SEARCH /) { $occurrences{ 1 + $index } = $log[$index]; } } return \%occurrences