## Perform test and call fraction only if test is true if ($str =~ /\d+_\d+) { $str = fraction($str); } ### subroutine fraction sub fraction { my $str = shift; # convert $str to fraction using mimetex syntax return $str; }