Your program does a lot of useless things. No point to store your files into arrays and then process the arrays, process the files directly. Also a lot of useless parens. This is a possible rewrite, about twice shorter (untested, I don't have data, and not sure it does exactly what you want, some of your code seemed a bit strange to me, I might have changed it the wrong way, not having data does not help):
use strict;
use warnings;
my %hash1;
open my $FH, "<", $ARGV[0] or die "Could not open input file $ARGV[0]
+$!";
while (chomp (my $line = <$FH>)) {
my $file1_element = (split /\t/, $line)[5];
$hash1{$file1_element} = $_;
}
close $FH;
open my $FH2, "<", $ARGV[1] or die "Could not open input file $ARGV[1]
+ $!";
while (chomp (my $line = <$FH2>)) {
my $file2_element = (split /\t/, $line)[5];
print $_ . "\t$hash1{$file2_element}\n" if exists $hash1{$file2_el
+ement};
}
Now, if you want to do this at the command line, you can just do this:
$ perl -e '
use strict;
> use warnings;
> my %hash1;
> open my $FH> , "<",m $yA RG%V[0] or die "Could not open input file $
+1ARGV[0;] $!";
> open my $FH, "<", $ARGV[0] or die "Could not open input file $ARGV[0
+] $!";
> while (chomp (my $line = <$FH>)) {
> my $file1_element = (split /\t/, $line)[5];
> $hash1{$file1_element} = $_;
> }
> close $FH;
> open my $FH2, "<", $ARGV[1] or die "Could not open input file $ARGV[
+1] $!";
> while (chomp (my $line = <$FH2>)) {
> my $file2_element = (split /\t/, $line)[5];
> print $_ . "\t$hash1{$file2_element}\n" if exists $hash1{$file2_elem
+ent};
> } ' file1.txt file2.txt
But why should you want to do this? Why not having a real program in a file? Command line instructions are good for very short code, not for this. I could probably reduce the code by another half on the command line, perhaps even a bit more than that, but this is still too long for a one-liner of a pure prompt command.
Edit: Modified slightly the code, as some things coming from the OP code did not seem right to me.