Well if you really like the look of the switch type construct, TIMTOWTDI...
SubSwitch.pm
package SubSwitch;
use strict;
use base 'Exporter';
our @EXPORT_OK = qw(
switch
case
);
our $SubSwitch = undef;
sub switch
{
my ($val, $func) = @_;
local $SubSwitch = $val;
$func->();
}
sub case
{
my ($val, $func) = @_;
if ($val ne $SubSwitch) { return; }
$func->();
}
1;
test.pl
#! /usr/bin/perl -w
use strict;
use SubSwitch qw(switch case);
switch ("foo", sub {
case ("bar", sub {
print "not here\n";
});
case ("foo", sub {
print "here\n";
switch ("bar", sub {
case ("bar", sub {
print "there\n";
});
});
});
case ("bar", sub {
print "still not here\n";
});
})