%to_find = ( 'Set-Cookie' => '1', 'Server' => '1', #etc so on and so forth ); while (<$socket>) { # split on the first colon, but leave the rest alone ($key,$rest) = split(/:/, $_, 2); print "$key: $rest\n" if ($to_find{$key}); }