in reply to not getting desired output

You need to escape the square brackets since you want to match a literal [4], so instead of

if($line =~ /Handling NSPAdvice for mechanism [4]/) { # the RE above would match "Handling NSPAdvice for mechanism 4"
try this:
if($line =~ /Handling NSPAdvice for mechanism \[4\]/) { # alternative: if ( index($line,'Handling NSPAdvice for mechanism +[4]')>=0 ) {
Analogue:
if ($line =~ /Authentication mechanism returned [[](\S*)[] +]/) {
...to...
if ($line =~ /Authentication mechanism returned \[(\-?\d+) +\]/) { # the RE above would match e.g. [4] -> $1=4, [-10] -> $1= +-10, etc.
HTH