(on freebsd 4-8) Third result doesn't look right to me; sub and gsub act the same. /usr/foo/otp/otp_src_R10B-7>bin/erl Erlang (BEAM) emulator version 5.4.9 [source] Eshell V5.4.9 (abort with ^G) 1> regexp:gsub("foo","o$","Z"). {ok,"foZ",1} 2> regexp:gsub("foo","^","Z"). {ok,"Zfoo",1} 3> regexp:gsub("foo","$","Z"). {ok,"foo",0}