while () # or wherever those lines come from { chomp; my( $num, $str ) = split ' ', $_, 2; $str =~ s/^\d+,\s*//; $hash{$num} = $str; } #### while () # or wherever those lines come from { /^(\d+)\s+\d+,\s*(.*)/ and $hash{$1} = $2; }