my $mac = 'ff:ff:ff:ff:ff:ff'; $mac =~ s[^ (?: ( [0-9A-Z]{1,2} ) : ){5} ( [0-9A-Z]{1,2} ) $] [ sprintf '%02s' x 6, $1, $2, $3, $4, $5, $6 ]iex;