use CGI qw(:standard); print header(), start_html(-title => 'Textarea madness!', -script=> <<'EndJS', function fixTextarea ( elemId ) { var box = document.getElementById(elemId); var height = Math.floor( box.value.length / 50 ); var newlines = box.value.match(/(\n)/g); if ( newlines ) height += Math.floor( newlines.length * .7 ) + 3; if ( height < 3 ) height = 3; if ( height > 40 ) height = 40; box.style.height = height + 'em'; } EndJS ), h2("Textarea with JavaScript assisted dynamic resize"), start_form(), textarea( -style => 'width:40em;line-height:120%;overflow:auto;', -id => 'response', -onfocus => "fixTextarea('response')", -onkeypress => "fixTextarea('response')", -name => 'response', ), script({-type=>'text/javascript'}, # call it up front "fixTextarea('response')" ), end_form();