if ($str =~ s/\0$//) { print "found NUL byte at the end of '$str'\n"; }