You need something like preg_replace_callback()
to have a callback called against all matches.
Try:
$string = 'abcd'.hex2bin(23).'abc'.hex2bin(24);
$text = preg_replace_callback('/[\\x20-\\x25]/', function($matches) {
$string = bin2hex($matches[0]);
return "[HEX:{$string}]";
}, $string);