$string = "COM7:"; $string =~ s/(.)(.)?/sprintf("0x%02X%02X\n",ord($2),ord($1))/seg; print "${string}0x0000\n";