use Tie::File; tie my @file_array, 'Tie::File', $filename foreach (@file_array) { if (/^([^:]+)(?::[^:]*){6}:([^:+]+):/) { # this regexp can probably be improved. $users{$1} = $2; # you can add a debug print here if you want. } } untie @file_array;