#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file_file='file.txt'; my @regexp=( qr/\.txt$/, qr/\.csv$/, qr/\.ini$/, qr/\.cnf$/, ); open(my $in_fh, '<', $file_file) or die("Error open $file_file ($!)\n"); my @files=( [ ], [ ], [ ], [ ], ); while(my $line=<$in_fh>) { chomp($line); my $pos (0..$#regexp) { if($line=~$regexp[$pos]) { puhs(@{$files[$pos]},$line); } } } print Dumper(\@files);