#! /usr/bin/perl -w use strict; use 5.018; # test errmsg match # sample (and partial; see the chunking in the next code) errmsgs from file: # ResultError: 404.... ( or 301 etc.) # ResultError: SSLError: [Errno 1] _ssl.c:504:.... my $errmsg = qr[ResultError:.*?(?=)]; my @data_sample = ( 'ResultError: 404 Not Found', 'ResultError: SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed', ' abcde ' ); my $data_line; for $data_line(@data_sample) { if ( $data_line =~ /$errmsg/ ) { say "\t FOUND IT: $data_line \n"; } else { say "\t NO MATCH ON $data_line \n"; } }