$PLUGIN_DIR = $MT_DIR;
($MT_DIR, $PLUGIN_ENVELOPE) = $MT_DIR =~ m|(.*[\\/])(plugins[\\/].*)$|i;
The sltool script included with SpamLookup seems to use more robust code:

if ($MT_DIR =~ m!plugins[\\/]!) {
$PLUGIN_DIR = $MT_DIR;
($MT_DIR, $PLUGIN_ENVELOPE) = $MT_DIR =~ m|(.*[\\/])(plugins[\\/].*)?$|i;
}
$MT_DIR .= '/' unless $MT_DIR =~ m![\\/]$!;