$_ = '1.2.3.4.5.6 foo bar'; if (/((?:\d+\.)+(\d+)/) { my @matches = (split(/\./, $1), $2) }