convert perl code to shell script

This is about how to Monitoring folder for new files using shell script

im doing a project using smsserver tools 3. i have used a perl script
to handle incoming messages. the content of each message must be
directed to a java program. this program generates the answer to reply
to the user .so i need to call the java program from the perl code.
this is my perl code

//******************************************************************************************************************************************

#!/usr/bin/perl -w

use strict;
use File::Monitor;
use File::Monitor::Object;


my $number = '';
my $msgFrom = '';

my $outgoing = "/home/T/Documents/run/outgoing/";
my $extract ="/home/T/Documents/run/extract part/";

my $temp = '/var/spool/sms/incoming';

my $monitor = File::Monitor->new();
my $newline = 0;

$monitor->watch( {
        name        => "$temp",
        recurse     => 1,
        callback    => \&Test,
    } );

$monitor->scan;

for (my $i=0; $i < 100; $i++)
{
      my @changes = $monitor->scan;
      sleep 5;
}

sub Test
{
      my ($name, $event, $change) = @_;

      my @adds = $change->files_created;
      my @dels = $change->files_deleted;

      if(@adds){

                print "Added: ".join("\nAdded: ", $adds[0])."\n"; # if  @adds;
                my $filename = $adds[0];
                open (INFILE, $filename); # if @adds;
                 while (my $line = <INFILE>) {
                chomp $line;

                         $line = lc($line);

                         if ($newline == 1) {
                                  $msgFrom = $msgFrom.$line;
                                printf "*************".$msgFrom;
                        }

                         if ($line =~ /^from: (.*)/) {
                                  $number = $1;
                         } elsif (length($line) == 0) {
                          $newline = 1;
                 }
    }
                close INFILE;


                open(OUTFILE1 , ">".$number.".txt");

                print OUTFILE1 ("hi gfdg");
                close OUTFILE1;

                open(OUTFILE, ">".$outgoing."sms".$number."-".int(rand(100000)));
#open for write, overwrite
                print OUTFILE ("To: ",$number); #write text without  newline
                print OUTFILE "\n\n";
                print OUTFILE join(',','hi is this working '); #write  text
                print OUTFILE "\n"; #write newline
                close OUTFILE;
        }
}

//******************************************************************************************************************************************

can anyone help me to write this perl code in shell script ?

or is there a way to call java programe inside perl code?

You can try piping your output to the java program.

open OUTFILE, '|-', 'javaprog' or die "open: $!";
print OUTFILE <<"EOF"
blah $foo
blah $bar
EOF

in the perl code for file monitoring i download some files
use File::Monitor;
use File::Monitor::Object;

so in shell scripting do i need some files to do file handling inside a folder?
because in this project i need to get all incoming message to some folder to direct to a java program and automatic generate the reply for the message .