#!/usr/local/bin/perl -w use strict; $_ = '00a0c801adc6'; s/([\w]{2})(?!$)/$1:/gio, "\n
"; print "$_\n
"; #### s/ ([\w]{2}) # matches a pair of letters/numbers (?!$) # matches NOT end of string (zero-width negative lookahead assertion) /$1:/giox; # replace pair with trailing colon