# Save input from STDIN into $file my $file = ; # If $file matches one letter or number, then underscore # and then .dat, then do the block. By the way, you are # missing the closing bracket for the block. :) if ($file=~/[a-zA-Z0-9_]\.dat/){ # Open file or die with some error. open(DATOS, "$file") || die "No se puede abrir el archivo, o no existe en el directorio"; # Read file line by line while (){ # Initialize array @lines my @lines; # Initialize array @line and make it equal to an # empty array @lines, if the line from file starts with # the digit. my @line = @lines if m/^\d/; # Print empty array @lines print "@lines";