use strict; use warnings; my $str='1,zxc,2,asd,3,qwe'; foreach ( $str =~ /([^,]+,[^,]+)/g ) { my ($k, $v) = split /,/; print "Do something with key $k and value $v\n"; } #### foreach (my ($k,$v) = $str =~ /([^,]+),([^,]+)/g) {