#Function call That works my $hashData = truncateText($inputText, "begin", "end"); #Desired function call that doesn't work my $hashData = truncateText($inputText, "begin =>", "end =>"); #Truncating Function sub truncateText{ #Truncates text by removing everything before and and after the passed in variables my($text, $beginString, $endString) = @_; my $truncatedText; if($text =~ /\b\Q$beginString\E\b(.*?)\b\Q$endString\E\b/s){ $truncatedText = $1; } return $truncatedText; }