use strict; use warnings; # Put your subs here before any file-scope variables. # That makes it clearer that each sub does not depend on # anything other than the parameters passed to it. sub ownertbl { my ( $sortby, $ascdesc, $letter ) = @_; # added leading "my" # ... } # put your other subs here... # Now define your lexical variables after the subs... my ($ownsel, $sortby, $letter, $ascdesc, $t); if ( $cgi->param ) { if ( defined ( $cgi->param( 'sortby' ) ) ) { $sortby = $_; # this looks wrong to me } else { $sortby = "name"; } if (defined ( $cgi->param( 'ascdesc' ) ) ) { $ascdesc = $_; # ditto } else { $ascdesc = "desc"; } if (defined ( $cgi->param( 'letter' ) ) ) { $letter = $_; # ditto } else { $letter = " "; } ownertbl( $sortby, $ascdesc, $letter ); # now these three variables are properly passed to the sub } else { homepage(); }