in reply to Unserialize String to hash

Lots of ways to do this task. In Perl, the field width stuff is not important. Below is one way. A "match global" regex is used to extract the pairs and then a while loop puts them into a hash.
#!/usr/bin/perl -w use strict; use Data::Dumper; my $x = 'a:1:{s:4:"Name";s:5:"sandy";s:5:"sport";s:7:"cricket";}'; my %hash; my ($key,$value); my @tokens = $x =~ m/"(.*?)"/g; $hash{$key}= $value while (($key, $value)= splice(@tokens,0,2)); print Dumper(\%hash); __END__ prints $VAR1 = { 'sport' => 'cricket', 'Name' => 'sandy' };