use Digest::MD5 qw( md5_hex ); my $public_part = "username"; my $secret_key = "foobar"; my $hash = md5_hex( join ':', $secret_key, md5_hex( join ':', $public_part , $secret_key ) ); my $session_key = "$public_part:$hash";