/^(?:$part:){5}$part$/; my @parts = split /:/; #### my @parts = /^($part):($part):($part):($part):($part):($part)$/ #### my $re_mac_bUK = '(?: ( [0-9A-Z]{1,2} ) : )' x 5 . '( [0-9A-Z]{1,2} )'; sub replace_bUK { s[^ $re_mac_bUK $] [ sprintf '%02s' x 6, $1, $2, $3, $4, $5, $6 ]ex; } #### my $re_mac_ihb = qr/(?:$part:){5}$part/ . ''; sub replace_ihb { /^ $re_mac_ihb $/x; $_ = sprintf '%02s' x 6, split /:/; } #### /^(...$)/m #### $_ = 'a ' x 1000; s/(\s+)$//; # Slower s/(\s+$)//; # Faster