in reply to string initialization error

It looks like you set $page to "" and then possibly set it to undef in the following line if there is no query parameter named "page". By the time perl compares $page to 'main', it's getting an undef value.

You probably meant something like: my $page = $query->param("page") // '';

or: my $page = $query->param("page") || '';

Replies are listed 'Best First'.
Re^2: string initialization error
by haukex (Archbishop) on Dec 21, 2018 at 15:44 UTC
    or: my $page = $query->param("page") || '';

    Caveat: That will also assign '' to $page if $query->param("page") returns 0 or "0" (the same applies to hippo's answer).

    TIMTOWTDI: Another alternative to the code from the OP may be (at least on Perl v5.12 and up):

    sub loadPage { my $page = $query->param("page"); if ( length($page) && $page eq 'main' ) { loadMainPage(); return 1; } }