#!/usr/bin/perl -- use strict; use warnings; use LWP; use Data::Dump(); sub LWP::Protocol::http::SocketMethods::format_request { package LWP::Protocol::http::SocketMethods; my( $socket, $method, $fullpath, @h ) = @_; #~ my $req_buf = $socket->Net::HTTP::Methods::format_request($method, $fullpath, @h, 'Keep-Alive',666); ## fail, adds another header my $req_buf = $socket->Net::HTTP::Methods::format_request($method, $fullpath, @h ); $req_buf =~ s{Keep-Alive: 300}{Keep-Alive: 30}g; ## win, removes existing header Data::Dump::dd( $req_buf ); return $req_buf; } LWP::UserAgent->new( keep_alive=>1 )->get( q{http://127.0.0.1:80/} )->dump; __END__ "GET / HTTP/1.1\r\nTE: deflate,gzip;q=0.3\r\nKeep-Alive: 30\r\nConnection: Keep-Alive, TE\r\nHost: 127.0.0.1:80\r\nUser- Agent: libwww-perl/6.15\r\n\r\n" HTTP/0.9 200 Assumed OK Client-Date: Tue, 24 Apr 2018 23:25:20 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 Echo: GET / HTTP/1.1\r Echo: TE: deflate,gzip;q=0.3\r Echo: Keep-Alive: 30\r Echo: Connection: Keep-Alive, TE\r Echo: Host: 127.0.0.1:80\r Echo: User-Agent: libwww-perl/6.15\r Echo: \r\n