sub probability { my ($source, $target, %hash) = @_; return $hash{$source}{$target}; } my $proba = probability($key_level1, $key_level2, %hash);