use constant MAX_CHARS => 1100; if ( length($str) > MAX_CHARS ) { $str = substr( $str, 0, MAX_CHARS ); }