#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; sub charAt { return substr $_[0], $_[1], 1; } my $line = "foo=1.0 bar=2.0"; my @pos = grep { charAt($line, $_) eq '=' } (0 .. (length($line) - 1)); print Dumper @pos; my %table; foreach my $kv_pos (@pos) { my $k1 = $kv_pos - 1; my $v0 = $kv_pos + 1; for (my $k0 = $k1; $k0 > 0 && $line[$k0] ne ' '; --$k0) {} for (my $v1 = $v0; $v1 < length($line) && charAt($line, $v1) ne ' '; ++$v1) {} $table{substr($line, $k0, $k1-$k0)} = substr($line, $v0, $v1-$v0); } print Dumper \%table;