my %hash; while ( ) { my ( $key ) = ( m/^(\w+)/ ) or next; $hash{$key} = 'whatever'; }