porting perl version to erlang