use B qw( svref_2object ); # https://perldoc.perl.org/perlapi#SvPVX sub SvPVX { svref_2object( \$_[0] )->PV } my $s = "0123456789"; printf "%x\n", SvPVX( $s ) while $s =~ /\G./g;