Perl: GET Web Page Content

By Xah Lee. Date: . Last updated: .

In Perl, the easiest way to get a webpage is to use the Perl program HEAD or GET usually installed at /usr/bin. For example, in shell, type:


It'll return the web page content. You can save it to a file by GET > myfile.txt.

HEAD and GET are two calling methods of the HTTP protocol. The Perl script are named that way for this reason. [see HTTP Protocol Tutorial]

For more contorl, use LWP::Simple or LWP::UserAgent. Both of these you need to install.

# -*- coding: utf-8 -*-
# perl

# get web page content

use strict;
# use LWP::Simple;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
my $url='';
my $request = new HTTP::Request('GET', $url);
my $response = $ua->request($request);
my $content = $response->content();
print $content;

In the above, the $ua -> timeout(120); is a Object Oriented syntax.

If you have a question, put $5 at patreon and message me.


  1. Perl Overview
  2. Version String
  3. Help System


  1. Quoting String
  2. Format String
  3. String Operations
  4. True, False
  5. if then else
  6. Loop
  7. List / Array
  8. Loop Thru List
  9. Map f to List
  10. List Comprehension
  11. Hash Table
  12. Function Optional Param
  13. regex
  14. Split Line by Regex


  1. Sort List, Matrix, Object
  2. Sort Matrix
  3. List Modules, Search Paths
  4. Write a Module
  5. Read / Write File
  6. Traverse Dir
  7. Find / Replace
  8. Complex Numbers
  9. System Call
  10. Compress / Decompress gzip
  11. Get Env Var
  12. GET Web Content
  13. Unicode 🐪
  14. Convert File Encoding
  15. Sort Unstable