my $re_mac_ihb = qr/(?:$part:){5}$part/ . ''; sub replace_ihb { /^ $re_mac_ihb $/x; $_ = sprintf '%02s' x 6, split /:/; }