Generate a UUID in Perl

Perl is a high-level, general-purpose, interpreted, dynamic programming language.

First developed in 1987 by Larry Wall, the latest version is Perl 5, which runs on 100s of platforms and is used in a wide range of contexts including web development, system administration, internet duct-tape and more. It was termed the "first postmodern computer language" by Mr. Wall in a talk in 1999.

How to Generate a UUID in Perl

Although the Perl programming language itself does not have built-in support for generating a UUID or GUID, there are quality 3rd party, open-source packages that you can use instead.

We recommend the UUID package. It can generate version 1, 3, 4, 5, 6, or 7 UUIDs. All are variant 1, meaning compliant with the OSF DCE standard as described in RFC4122.

Installing the UUID package from CPAN

Perl packages are typically installed from the Comprehensive Perl Archive Network (CPAN). It is common to use the cpan minus installer. You can install the UUID package with this command:

% cpanm UUID

Generating UUIDs

With the UUID package installed, you can now use it in your Perl code.

use strict;
use warnings;
use UUID qw(uuid4);
my $uuid = uuid4();
print "Your v4 UUID is: $uuid\n";

Explanation

  • Lines #1 and #2 are good practice, ensuring common errors are caught and useful warnings are emitted.
  • Line #3 includes the UUID module and imports the uuid4 function into the current package.
  • Line #5 generates a Version 4 UUID and saves it in the variable, $uuid. The uuid4() function returns a new, random, Version 4 UUID.
  • The output from line #7 will be something like:
    Your v4 UUID is: 374fe2ea-2034-420d-8d69-c49122fe6bed
    

The UUID package has a number of other functions, such as those for generating other UUID versions and for parsing UUID strings. You can read more about the UUID package on its MetaCPAN page.

Special thanks to Adam Clarke for the information on generating UUIDs in Perl.


How can we improve this page? Let us know!




The UUIDs generated by this site are provided AS IS without warranty of any kind, not even the warranty that the generated UUIDs are actually unique. You are responsible for using the UUIDs and assume any risk inherent to using them. You are not permitted to use the UUIDs generated by this site if you do not agree to these terms. Do not use any UUIDs found on cached versions of this page.
Privacy Policy
This website uses cookies. We use cookies to personalise content/ads and to analyse our traffic.

The UUIDs generated by this site conform to RFC 4122 whenever possible.
Read more about UUIDs at Wikipedia.
Check out our developer API.

Copyright © 2026 TransparenTech LLC. All Rights Reserved. Contact Us.