sub trim { if ( !@_ && !defined(wantarray) ) { carp 'Useless use of trim with no arguments in void return context (did you mean "trim($_)"?)'; return; } if ( !@_ ) { carp "Useless use of trim with no arguments"; return; } @_ = @_ if defined wantarray; for (@_) { s/\A\s+//; s/\s+\z// } return wantarray ? @_ : "@_"; }