use strict; my $exampleinput = q(1 | p1=v1,p2=v2 | p3=v3,p4=v4); sub processrow( $ $ ) { my ( $hashref, $input ) = @_; my @condition = split( /\s*\|\s*/, $input ); my $index = shift( @condition ); $hashref->{$index} = [ map { { map { $_->[0] => $_->[1] } map { [ split( /=/, $_ ) ] } map { split( /,/, $_ ) } $_ } } @condition ]; } my %examplehash = (); processrow( \%examplehash, $exampleinput ); { use Data::Dumper; print( Dumper( \%examplehash ) ); }