Call: (480) 382-8464

Perl MD5sum Using Digest::MD5

There is a binary utility on most flavors of linux that allows you to compare if a file is exactly the same as another. Here is how you get MD5 info using Perl:

I wrote something similar a few years ago and couldn’t find it. So I googled the docs on Digest::MD5 and found this wonderful example.

You would want to use an MD5 sum for comparing a file after you’ve transmitted it, to ensure it is the same file without errors.

Perl MD5Sum Using Digest::MD5


# credit:

use warnings;
use strict;
use Digest::MD5;
sub md5sum{
  my $file = shift;
  my $digest = "";
    open(FILE, $file) or die "Can't find file $file\n";
    my $ctx = Digest::MD5->new;
    $digest = $ctx->hexdigest;
    print $@;
    return "";
  return $digest;
sub usage{
  print "usage: ./ filename\n";
  exit 1;
if($#ARGV + 1 != 1){

my $fname = $ARGV[0];
my $md5 =  md5sum($fname);
if($md5 ne ""){
  print $md5." ".$fname."\n";
  exit 1;
exit 0; 

Leave a Reply

Your email address will not be published. Required fields are marked *

Main Offers/Services

Hosting and website related services offered by Digital Crunch:

Managed VPS Hosting

Server Updates, Module/Software Installs, Firewall, Security, Hosting Management, Wordpress - let us manage it for you

Hosted Email

Setup and Maintain Business Class, Secure Email Hosting including spam protection and 25GB of storage space

Linux Consulting

Server Updates, Module/Software Installs, Firewall, Security, Hosting, Wordpress and Apps, anything related to Linux

Email Marketing Services

We broadcast your content to your list, capture leads for you, follow up on schedules, make more sales for you

Website Maintenance

Content updates, menu changes, graphics changes, adding content, getting links, building traffic, building sales funnels

Hosting Tutorials

Tutorials we've written for other customers that like to get their hands dirty and learn about hosting