#!/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 baz=hoge"; my @pos = grep { charAt($line, $_) eq '=' } (0 .. (length($line) - 1)); my %table; while ($line =~ /([^ ]+)=([^ ]+)/g) { $table{$1} = $2; } foreach my $kv_pos (@pos) { my($k0, $k1, $v0, $v1); for ($k0 = $k1 = $kv_pos - 1; $k0 > 0 && charAt($line, $k0-1) ne ' '; --$k0) {} for ($v0 = $v1 = $kv_pos + 1; $v1 < length($line) && charAt($line, $v1-1) ne ' '; ++$v1) {} $table{substr($line, $k0, $k1-$k0+1)} = substr($line, $v0, $v1-$v0+1); } print Dumper @pos; print Dumper \%table;