There's nothing related to @dirs that I see wrong with this snippet of code ( but $choice = chomp(<STDIN>); should be chomp( $choice = <STDIN> ); ). I ran the snippet fine with
the chomp change (and menu() and title() commented out). Is there something in the menu function that is clobbering @dirs?