if (my @match = split /\s+/) { if ($match[-2] =~ /^\d{1,3}$/ and $match[-1] !~ /\D/) { $match[-2] = $count++; } $_ = "@match\n"; }