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