#!/bin/bash INPUT="A string" func() { echo $INPUT | perl -e '$in=; $in=~s/string/thing/g; print $in' } RESULTS=$(func) echo $RESULTS #### A thing