while () { next if /^#|^\s*$/; ... #### while () { print "$1\n" if /^snmpmanager\s+(\d+\.\d+\.\d+\.\d+)\s+;\s+communityname/; } __DATA__ #test file #example: snmpmanager 10.52.37.99 ; communityname public