use strict; use GDBM_File ; my %hash; tie %hash, 'GDBM_File', 'words.dbm', &GDBM_WRCREAT, 0640; my $dict_file = '/usr/share/dict/longlist'; open DICT, "<$dict_file" or die "open($dict_file): $!"; my @words = (); my $prefix = ''; while() { chomp; $_ = lc($_); if(substr($_, 0, 3) ne $prefix) { if(@words) { $hash{$prefix} = join(' ', @words); @words = (); } $prefix = substr($_, 0, 3); } push @words, $_; } untie %hash ;