You can use File::Slurp module:
use File::Slurp qw/read_file/;
my $text = read_file( 'filename' ) ;
$text =~ s/\n/ /g;
print $text;
If you don't want to use the module, you can try this:
#!/usr/bin/perl
use strict;
use warnings;
my $text;
open my $fh, "<", "./alarm.pl" or die $!;
{
local $/; # enable localized slurp mode
$text = <$fh>;
}
close $fh;
$text =~ s/\n/ /g;
print $text;