Index: languages/perl6/src/builtins/any-str.pir
===================================================================
--- languages/perl6/src/builtins/any-str.pir	(revision 35423)
+++ languages/perl6/src/builtins/any-str.pir	(working copy)
@@ -21,7 +21,7 @@
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('capitalize,chop,chomp,chars,:d,:e,:f,index,lc,lcfirst,rindex,ord,substr,uc,ucfirst,unpack', 'from'=>$P0)
+    '!EXPORT'('capitalize,chop,chomp,chars,:d,:e,:f,index,lc,lcfirst,rindex,ord,substr,trim,uc,ucfirst,unpack', 'from'=>$P0)
 .end
 
 
@@ -128,6 +128,39 @@
        .return (retv)
 .end
 
+=item trim()
+
+Remove leading and trailing whitespace from a string.
+
+=cut
+
+.sub 'trim' :method :multi(_)
+    .local string s
+    .local int start, end, temp, len
+    .local int not_whitespace
+    s = self
+    start = 0
+    end = length s
+    if end == 0 goto donetail
+  loop:
+    not_whitespace = is_cclass 32, s, start
+    unless not_whitespace goto done
+    inc start
+    goto loop
+  done:
+    temp = end
+  tail:
+    dec temp
+    not_whitespace = is_cclass 32, s, temp
+    unless not_whitespace goto donetail
+    end = temp
+    goto tail
+  donetail:
+    len = end - start
+    s = substr s, start, len
+    .return(s)
+.end
+
 =item comb()
 
 Partial implementation for now, returns a list of strings
