As I said in a private email, grabbing the subpackage from OpenBSD::PkgPath is a bit more complex than you thought.
The following tweak to PackingElement should make it obvious how to grab the subpackage if it exists. Bonus: PkgCreate will refuse to create invalid packages. Note that the ports infrastructure creates FULLPKGPATH-sub in a deterministic order (register-plist wouldn't work otherwise) but it's not really documented in pkg_create(1), the only rule is that you can't have more than one subpackage, which is easy to check. Index: OpenBSD/PackingElement.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackingElement.pm,v retrieving revision 1.282 diff -u -p -r1.282 PackingElement.pm --- OpenBSD/PackingElement.pm 8 Jun 2022 14:57:12 -0000 1.282 +++ OpenBSD/PackingElement.pm 22 Jun 2022 09:01:30 -0000 @@ -2156,9 +2156,19 @@ sub new { my ($class, $fullpkgpath) = @_; my ($dir, @mandatory) = split(/\,/, $fullpkgpath); - return bless {dir => $dir, + my $o = + bless {dir => $dir, mandatory => {map {($_, 1)} @mandatory}, - }, $class; + }, $class; + my @sub = grep {/^\-/} @mandatory; + if (@sub > 1) { + print STDERR "Invalid $fullpkgpath (multiple subpackages)\n"; + exit 1; + } + if (@sub == 1) { + $o->{subpackage} = shift @sub; + } + return $o; } sub fullpkgpath