#this one returns you text/plain part return $ct{'text/plain'} if exists $ct{'text/plain'}; # and these are not executed it there's text/plain part return $ct{'text/html'} if exists $ct{'text/html'}; # these are not executed at all an they are not correct! # parts[0] may contain text/html and parts[1] text/plain return $parts[0] if $which =~ /text/; return $parts[1] if $which =~ /html/