my $msg; if (/msg=(.*?) Src/) { $msg = $1; } #else { # possible error message here, whatever is appropriate #}