# assume $sql contains an sql statement read from a file; # we want to print the statement, showing visible ascii # characters as-is, and converting other things to hex: @bytes = split //, $sql; for ( @bytes ) { if ( /[\x21-\x7e]/ ) { print " $_"; } else { printf( " %0.2x", ord ); } }