The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


MIME::Types - Perl extension for determining MIME types and Transfer Encoding


  use MIME::Types qw(by_suffix by_mediatype);

  my ($mime_type, $encoding) = by_suffix(FILENAME);
  my $aref = by_suffix(FILENAME);

  my @list = by_mediatype(MEDIATYPE);
  my $aref = by_mediatype(MEDIATYPE);


NOTE: This is ALPHA code. There are no guarantees that any of the subroutines described here will not have their names or return values changed.

This module is built to conform to the MIME types standard defined in RFC 1341 and updated by RFC's 1521 and 1522. It follows the collection kept at


The following functions are avilable:


This function takes either a file name suffix or a complete file name. It returns a two-element list or an anonymous array if the suffix can be found: the media type and a content encoding. An empty list is returned if the suffix could not be found.


This function takes a media type and returns a list or anonymous array of anonymous three-element arrays whose values are the file name suffix used to identify it, the media type, and a content encoding.

If the media type contains a slash (/), it is assumed to be a complete media type and must exactly match against the internal table. Otherwise the value is compared to all the values in the table via a regular expression. All regular expression codes are supported (except, of course, any string with a slash in it). Thus, calling by_mediatype("application") will return a large list.


Jeff Okamoto <>.

Updated by David Wheeler <>.

Inspired by the program by Dan Sugalski <>.