#!/usr/bin/perl -wT use strict; use Data::Dumper; my $del = '~'; my $file="file.txt"; my %hash; open(DB,"$file") || die "$!"; while(){ my ($nick,$phone,$name,$cell) = split/$del/; #split on $del. %_ = (nick=>"$nick",phone=>"$phone",name=>"$name",cell=>"$cell"); $hash{$nick}={%_}; } print Data::Dumper->new([\%hash],[qw(hash)])->Indent(2)->Quotekeys(0)->Dump; # the above is from the Data::Dumper tutorial on this site.