in reply to Insert colons into a MAC address

If you want to keep using a regexp, then:

$mac =~ s/^(..)(..)(..)(..)(..)(..)$/$1:$2:$3:$4:$5:$6/ if $mac =~ /^[0-9A-F]{12}$/i;

Replies are listed 'Best First'.
Re^2: Insert colons into a MAC address
by CountZero (Bishop) on Jan 13, 2012 at 21:35 UTC
    Instead of using the [0-9A-F] character class (more correct would be [0-9a-fA-F] and then you can drop the i parameter) you can use \p{Hex}.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James