my %kinds = ( type1 => { sender => qr/^me$/, subject => qr/this/, body => qr/that/ }, type2 => { sender => qr/^you$/, subject => qr/these/, body => qr/those/ }, # ... ); sub classify_msg { my ( $msg ) = @_; # $msg is expected to be a hash ref my @matches = (); for my $type ( keys %kinds ) { my $matched = 1; for my $test ( @{$kinds{$type}} ) { $matched &= ( $$msg{$test} =~ $kinds{$type}{$test} ); last unless $matched; } push @matches, $type if ( $matched ); } return \@matches; }