$line = 'key1|value1|key2|value2|'; while ( $line =~ m/([^|]+)\|([^|]+)\|/g ){ $file{$1}=$2; }