We help IT Professionals succeed at work.

Decoding UTF-8 in an e-mail

inscribble82 asked
Medium Priority
Last Modified: 2012-05-06
I am trying to extract data from an e-mail which is utf-8 encoded in perl

In particular I need to read the subject line:
Subject: =?utf-8?B?SU5WRU5UT1JZIERFUExFVEVE?=

I'm pretty sure that I need to use the Encode.pm module but I just can't get it to work.
Watch Question

Top Expert 2009
Your string doesn't look like utf-8.  It looks like base64, but with some extra stuff.  Here is a script that'll convert it.

use MIME::Base64::Perl;
my $Subject = '=?utf-8?B?SU5WRU5UT1JZIERFUExFVEVE?=';
print "Subject: $Subject\n";
$Subject = DecodeSubject($Subject);
print "Subject: $Subject\n";
sub DecodeSubject {
	my $s=shift;
	$s =~ s/^=\?utf-8\?B\?(.*)\?=$/$1/s;
	return decode_base64($s);

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Works a treat. Thank you very much.

I think I'm a bit confused between Character Sets and Encoding. I need to o a bit more reading!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.