in reply to How to write good code?

The first step should be to make the code correct. For example, use eq for string comparison (and not ==). Also use strict; use warnings;, that would have caught that mistake.

IMHO your second solution is much more readable, but it suffers from bad indentation. Fix that, and be happy.

Of course you could also use a dispatch table:

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); } } }