open my $a,";# prints the file contents as expected print $1 if <$a> =~ m/(error.*)/; # Nothing printed though the files has the line containing error key word. my @b=<$a>;grep {$_ =~ /error/} @b;# This does the trick and wondering why the above line doesn't work