my %REGEX = ( header = [qr/^(?!START:|END:)([^*: ][^:]+):(.+)\n/, \&header], starttime = [qr/^START:\s*(.+)\n/, \&etc], endtime = [qr/^END:\s*(.+)\n/, \&etc], lineitem = [qr/^(?:\* | )([^:]+):(\d+):(.+)\n/, \&etc] ); #... #You could even use constants here to make things easier. # 0 = RE; 1 = FUNCTION; or something. for my $rex_table (keys %REGEX) { if (my @m = $line =~ $rex_table->[0]) { $rex_table->[1]->($r,@m); next LINE; } }