#define the sub sub strip_space { # get our parameter my $val = $_[0]; # if not given a reference, return false return false if ref($val) ne "SCALAR"; # remove whitespace and retrn true on success $$val =~ s/\s+//g; return 1; } # and call said sub $test = "this will have no spaces!"; print $test if strip_space($test); print $test if strip_space(\$test);