if ($line =~/JAP/) { # Logic to print to the Japanese file...; } elsif ($line =~/GER/) { # Logic to print to the German file...; } else { # Logic to print to the English file...; };