if ($line =~ /Authentication mechanism returned \[(\-?\d+)\]/) { # the RE above would match e.g. [4] -> $1=4, [-10] -> $1=-10, etc.