Index: languages/perl6/t/spectest.data
===================================================================
--- languages/perl6/t/spectest.data	(revision 35458)
+++ languages/perl6/t/spectest.data	(working copy)
@@ -286,6 +286,7 @@
 S29-str/split-simple.t
 S29-str/sprintf.t
 S29-str/substr.t
+S29-str/trim.t
 S29-str/ucfirst.t
 S29-str/uc.t
 S29-str/unpack.t
Index: languages/perl6/src/builtins/any-str.pir
===================================================================
--- languages/perl6/src/builtins/any-str.pir	(revision 35458)
+++ 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 is_whitespace
+    s = self
+    start = 0
+    end = length s
+    if end == 0 goto donetrailing
+  trimleading:
+    is_whitespace = is_cclass 32, s, start
+    unless is_whitespace goto doneleading
+    inc start
+    goto trimleading
+  doneleading:
+    temp = end
+  trimtrailing:
+    dec temp
+    is_whitespace = is_cclass 32, s, temp
+    unless is_whitespace goto donetrailing
+    end = temp
+    goto trimtrailing
+  donetrailing:
+    len = end - start
+    s = substr s, start, len
+    .return(s)
+.end
+
 =item comb()
 
 Partial implementation for now, returns a list of strings
