$page = join "", @prep; # since the lines are in an array if (my ($tag) = $page =~ m//) { # call the appropriate sub based on the tag if ($tag eq 'a') { suba; exit; } elsif ($tag eq 'b') { subb; exit; } # ...etc... }