http://www.perlmonks.org?node_id=841399


in reply to Rearrange hex digits.

I don't see any way of modifying the algorithm of the regular expression to make it more comprehensible (maybe doing it in multiple steps?) but, when I want to make code more comprehensible, my first thought is documentation, and regular expressions can certainly take documentation. Utilizing the x modifier, the regular expression will ignore white space and comments (# delimited). See perlre. I also think uc might be more clear than your tr. Consider:

$job_id = uc $job_id; $job_id =~ s/^(..)(..)(..)(..) # Invert first 4 bytes (..)(..) # More comments ... (..)(..) (.{4}) (.{12}) $ /$4$3$2$1-$6$5-$8$7-$9-$10/x;

or the indentation/comment scheme of your choice.