#!/usr/bin/perl use warnings; use strict; print "Enter the name of your file, ie myfile.txt: ",; chomp( my $file = ); my %found; open my $fh, '>', 'freq_file.txt' or die "can't open this file: $!"; open my $fh2, '<', $file or die "can't open this file: $!"; while ( my $line = <$fh2> ) { $found{$_}++ foreach split /\s+?/, $line; } print $fh "Frequence\tValue Found", $/; print $fh $_, "\t\t", $found{$_}, $/ foreach sort keys %found; close $fh2 or die "can't close file: $!"; close $fh or die "can't close file: $!";