How about
```perl
my @parts = split(/@/, $principal);
my $user = join('@', @parts[0..$#parts-1]);
my $realm = $parts[$#parts];
```
?