#!/usr/bin/perl -w use strict; my $string = "21090412500011 209 070279501 9047 0 1111"; my @list = ("date", 6, "time", 4, "duration", 4, "calling-num", 15, "dialed-num", 18, "code-used", 4, "cond-code", 1, "ppm", 5, "auth-code", 13,); my @anotherlist; my $ptr = 0; while(1){ push(@anotherlist, shift(@list)); my $length = shift(@list); push(@anotherlist, substr($string, $ptr, $length)); $ptr += $length; last if $ptr >= length($string); } print "@anotherlist\n";