my %position_of = ( 'A' => 1, 'A#' => 2, # ... ); my %note_at = (); for my $note (keys %position_of) { $note_at{$position_of{$note}} = $note; }