my $msg = "new item x"; my $cmd = head \ $msg; if ( $cmd eq 'new') { if ( head \ $msg eq 'item') { ... } } elsif ( $cmd eq 'set') { ... }