To use bash functions you need to be in bash. So that puts you inside backticks or system when in a Perl script, where you are inside a bash process†. Then, inside that process, you can source the script with functions, what will bring them in, and execute them
funcs.sh
#!/bin/bash
function f1 {
t1=$1
u1=$2
echo "f1: t1=$t1 u1=$u1"
}
function f2 {
t2=$1
u2=$2
echo "f2: t2=$t2 u2=$u2"
}
and in Perl ("one-liner")
perl -wE'
@r = qx(source funcs.sh; f1 a1 b1; f2 a2 b2);
print "got: $_" for @r
'
where qx is the operator for backticks, but perhaps clearer. I use backticks in case you need return from those functions. One can also call bash explicitly (but read on)
perl -wE'
@r = qx(/bin/bash -c "source funcs.sh; f1 a1 b1; f2 a2 b2");
print "got: $_" for @r
'
Assignment to an array puts qx in list context, in which it returns the STDOUT of what it ran as a list of lines. This can be used to separate return from different functions, if they return a single line each. The a1,b1 and a2,b2 are arguments passed to f1 and f2.
Prints
got: f1: t1=a1 u1=b1
got: f2: t2=a2 u2=b2
This makes some (reasonable) assumptions.
However, qx will pass this through a shell because it concatenates its input to a string which is then analyzed for shell meta-characters to decide whether to run a shell, and the " are shell meta-characters. Then on a system where sh isn't linked to bash (but, say, to dash) this may not work.
On such a system run commands in a way that ensures that no shell gets its fingers on them, best by using one of the good modules for running external commands. An example with IPC::Run
use IPC::Run qw(run);
my @cmd = ('bash', '-c', 'source funcs.sh; f1 a1 b1; f2 a2 b2');
run \@cmd, \undef, \my $out, \my $err;
say "out: $out" if $out;
say "err: $err" if $err;
If there is no need for the return, but the functions only need to do their thing, you can use
system('/bin/bash', '-c', 'source ... ')
as in Håkon's answer. With system, supplying an argument list (as opposed to a string) ensures that no extra shell is called so this should work as it stands in any shell.
† It is /bin/sh really, but that is often relegated to bash. Things may need to be run differently if sh links to another shell, read on.
system 'bash', '-c', 'source shell_script.sh; func_1'