Convert curl to Perl

Convert curl commands to Perl code using LWP::UserAgent. curl2code runs entirely in your browser via WebAssembly — your data stays private. For Python, try our curl to Python converter. For Ruby, see curl to Ruby. Below are ready-to-use Perl examples.

How to copy curl from your browser

  1. 1

    Open DevTools

    Press F12 or Ctrl+Shift+I to open your browser developer tools.

  2. 2

    Go to the Network tab

    Click the Network tab and perform the action that triggers the HTTP request.

  3. 3

    Copy as cURL

    Right-click the request → CopyCopy as cURL. Then paste it above.

Frequently Asked Questions

What is Perl LWP?

LWP (Library for WWW in Perl) is the standard HTTP client library for Perl. The LWP::UserAgent module provides a full-featured client with cookie handling, redirects, proxy support, and SSL. Install with cpan LWP or apt install libwww-perl. curl2code uses LWP as the default for Perl conversions.

LWP vs HTTP::Tiny vs Mojo::UserAgent — which to use?

LWP is feature-rich and the traditional choice. HTTP::Tiny is a core module (no install needed) — great for simple requests. Mojo::UserAgent is modern with async support and WebSocket. For quick scripts, use HTTP::Tiny. For full features, use LWP. For similar scripting languages, see curl to Python or curl to Ruby.

How to handle authentication in Perl?

With LWP: $ua->default_header('Authorization' => 'Bearer token'). For Basic auth: $ua->credentials('host:port', 'realm', 'user', 'pass'). Or set headers per-request on the HTTP::Request object. curl2code converts -u and -H 'Authorization' flags to Perl syntax.

How to send multipart form data in Perl?

Use HTTP::Request::Common: POST($url, Content_Type => 'form-data', Content => [file => ['path/file.pdf']]). LWP handles multipart boundaries automatically. For additional fields, add key-value pairs to the Content array. curl2code converts -F flags to this format.

How to handle HTTP errors in Perl?

Check $response->is_success after each request. For error details: $response->status_line returns the status code and message. LWP returns a response object even on errors — check $response->code for the HTTP status. Use die or warn for error reporting.

How to parse JSON in Perl?

Use the JSON module: my $data = decode_json($response->content). For encoding: my $json = encode_json($hashref). Install with cpan JSON. For Perl 5.14+, consider JSON::PP (core module, no install). For more JSON-centric tools, see curl to Go.

How to set timeouts in Perl LWP?

Set on the UserAgent: my $ua = LWP::UserAgent->new(timeout => 30). This sets the overall request timeout in seconds. For connection timeout specifically, use IO::Socket::SSL options. LWP retries are not built-in — implement manually or use LWP::UserAgent::Determined.

How to use a proxy in Perl?

Set on the UserAgent: $ua->proxy(['http', 'https'], 'http://proxy:8080'). Or use environment variables: $ua->env_proxy reads HTTP_PROXY and HTTPS_PROXY. For no-proxy exceptions: $ua->no_proxy('localhost', '.internal'). curl2code converts -x flags to LWP proxy calls.

How to send a POST request with JSON body in Perl?

Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Perl using curl2code. The generated code uses $ua->post($url, Content_Type => 'application/json', Content => encode_json($data)). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the LWP::UserAgent code.

How to add Bearer token authorization in Perl?

Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates LWP::UserAgent code with the auth header: $req->header('Authorization' => 'Bearer YOUR_TOKEN'). curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.

How to set Content-Type header in Perl?

curl2code converts curl -H "Content-Type: application/json" URL to LWP::UserAgent code with the proper header: $req->header('Content-Type' => 'application/json'). For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct LWP::UserAgent API.

Useful Links

curl Guides

Convert curl to Other Languages