foreach my $chars (split(//,$input_string)) { $hexchars .= sprintf "%x", ord($chars); }