2015-02-27 16:35:29,832 [[48:1JK5DE9A]] INFO - performing task 2015-02-27 16:39:31,850 [[50:1EB1DB9F]] INFO - text: [[abcd.this is not needed]] mystring 2015-02-27 16:45:24,250 [[49:3CE1DB9A]] INFO - text: [[efghijk.this portion is also not needed]] mystring 2015-02-27 16:55:29,832 [[48:1JK5DE9A]] INFO - task done. 2015-02-27 16:55:31,850 [[50:1EB1DB9F]] INFO - text: [[lmn. again not needed]] mystring 2015-02-27 16:57:13,435 [[50:1EB1DB9F]] INFO - text: [[lmn. repetition. Again not needed]] mystring #### perl log.pl Can't use an undefined value as a symbol reference at log.pl line 30, <$_[...]> line 532 (#1) (F) A value used as either a hard reference or a symbolic reference must be a defined value. This helps to delurk some insidious errors. Uncaught exception from user code: Can't use an undefined value as a symbol reference at log.pl line 30, <$_[...]> line 532. at log.pl line 30 #### #!/usr/bin/perl -w use strict; use warnings; use autodie; use diagnostics; open my $read_log, '<', '/home/jay/test_output/tmp_app.log' or die $!; my $pattern = 'mystring'; my @log_lines=<$read_log>; my @all_lines_occurrences; my @all_extracts; my @unique_values; for(@log_lines){ if ($_ =~ m/.*$pattern.*/) { push (@all_lines_occurrences, $_); #print $_ "\n"; } } for (@all_lines_occurrences) { /^\d+\-\d+\-\d+ \d+:\d+:\d+\,\d+ \[(.*)\] .* \[(.*)\.(.*)\] .*\\n/; push (@all_extracts, $2); #print "target type: $2 \n"; } for(@all_extracts){ print $_ "\n"; } my @unique_values = do { my %seen; grep { !$seen{$_}++ } @all_extracts }; print "\n Unique values are:\n"; for (@unique_values) { print $_ "\n"; } close $read_log;