my %dispatch = ( daily => \&addDaily, test => \&addTest, ); foreach my $token (@tokens){ if($token =~ m/HREF="([a][^\/]*)/i) { my $extracted = $1; next unless $extracted =~ m/win/i; if (eval { $dispatch{$daily_test}->($extracted) } == 1 ) { push(@buildList, $extracted); } } }