sub data{ my @parts; my %data; my $i; my $x; my $new; my $value; my $key; my @values; $\ = "\n"; # parts is key, value + key @parts = split( /:/, $_[0]); $new = trim($parts[0]); for( $i = 1; $i <= $#parts; $i++ ){ # set right key $key = $new; @values = split( "\n", $parts[$i]); # last line is next key $new = trim( pop @values); foreach( @values ){ trim( $_ ); print $_; } # rest are values $data{$key} = join( "\n", @values); } while ( ($key, $value) = each (%data) ){ #print $key . '=>' . $value; } #print %data; }