use strict; use warnings; my $string = " info John 100 - 2000 Kent"; (my @words) = $string =~ /([A-Za-z]+)/g; (my @nums) = $string =~ /(\d+)/g; print "data:",shift @words," "; #the "info" word print "uneven stack error!" if (@words != @nums); while (@words) { print "",shift @words,":",shift @nums," "; } print "\n"; # prints: "data:info John:100 Kent:2000 " <= what you said you wanted