open(FH, $filehandle); while () { if(/$start_point/../$end_point/) { $line = $_; chomp $line; if ($line =~ m/SMS for Sub-service 1/) { $httpSMS++; } if($line =~ m/SMS for sub-service 2/) { $sipSMS++; } if($line =~ m/Error sending SMS/) { $errorSMS++; } } } close(FH); #### open(FH, $filehandle); while () { $line = $_; chomp $line; if($line =~ m/$start_point(.*)$end_point$/s) { if($line =~ m/SMS for Sub-service 1/) { $httpSMS++; } if($line =~ m/SMS for Sub-service 2/) { $sipSMS++; } if($line =~ m/Error sending SMS/) { $errorSMS++; } } } close(FH);