#1 [111.123.164.80] [123.126.126.126] 87 #000:00:00.0000.000.000 0 #+6/07/2000 04:39:00 PM SNMP: Get # Guess you have to ( pattern ) to store and use it with $1,$2,$3 , in your code you match it but you do not store it and hence print the line by itself if ($_ =~ /(\[.*\])\s+(\[.*\]).*(SNMP: Get$)/){ print "[$1] [$2] [$3]\n"; }