in reply to Using a regex to replace looping and splitting

"Would a Map work here?" -> yes.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1207789 use strict; use warnings; use Data::Dumper; my $big_string = 'special:1001:area_code:617|special:1001:zip_code:022 +05|special:1001:dow:0|special:1001:tod:14'; my %hash = map +(split /:/)[-2, -1], split /\|/, $big_string; print Dumper \%hash;

Use a split to split the big string on vertical bars, then split each part by colon, and keep the last two sub-parts (which are the key and value), to pass on through the map to the hash.