sub prompt_read { my $prompt = shift; print $prompt; my $response = ; $response =~ s/^\s*|\s*$//g; return $response; } Note: these "standard idioms" can be used, but with recent Perl's the more complex regex above is slightly faster. $response =~ s/^\s*//; # these 2 statements do the same $response =~ s/\s*$//; # but slightly slower