while ($string =~ /(\d+):(\d+)(?:,|$)/g) { $hash{$1} = $2; push(@array, $1); }