use warnings; use strict; my $file = 'filename.txt'; open my $fh, '<', $file or die "cant open : $!"; my @comp = sort <$fh>; close $fh; print "@comp";