# surround all uppercase characters in the passed parameter with *'s # and all lowercase characters with _'s sub transmogrify { my $string = $_[0]; $string =~ s/([A-Z])/*$1*/g; $string =~ s/([a-z])/_$1_/g; return $string; } $text = "I met this guy, and he looked like he might have been a hat check clerk at an ice rink, which in fact, he turned out to be. Let X = X."; $text = transmogrify($text); print $text;