while () { print if /^Host System (?!#)/; # or perhaps for more whitespace safety # print if /^Host\s+System\s+(?![#\s])/ }