Pterygium is a prevalent ocular disease characterized by abnormal conjunctival tissue proliferation, significantly impacting patients’ quality of life. However, the underlying molecular mechanisms driving pterygium pathogenesis remain inadequately understood. This study aimed to investigate gene expression changes following pterygium excision and their association with immune cell infiltration. Clinical samples of pterygium and adjacent relaxed conjunctival tissue were collected for transcriptomic analysis using RNA sequencing combined with bioinformatics approaches. Machine learning algorithms, including LASSO, SVM-RFE, and Random Forest, were employed to identify potential diagnostic biomarkers. GO, KEGG, GSEA, and GSVA were utilized for enrichment analysis. Single-sample GSEA was employed to analyze immune infiltration. The GSE2513 and GSE51995 datasets from the GEO database, along with clinical samples, were selected for validation analysis. Differentially expressed genes (DEGs) were identified from the PRJNA1147595 and GSE2513 datasets, revealing 2437 DEGs and 172 differentially regulated genes (DRGs), respectively. There were 52 co-DEGs shared by both datasets, and four candidate biomarkers (FN1, SPRR1B, SERPINB13, EGR2) with potential diagnostic value were identified through machine learning algorithms. Single-sample GSEA demonstrated increased Th2 cell infiltration and decreased CD8 + T cell presence in pterygium tissues, suggesting a crucial role of the immune microenvironment in pterygium pathogenesis. Analysis of the GSE51995 dataset and qPCR results revealed significantly higher expression levels of FN1 and SPRR1B in pterygium tissues compared to conjunctival tissues, but SERPINB13 and EGR2 expression levels were not statistically significant. Furthermore, we identified four candidate drugs targeting the two feature genes FN1 and SPRR1B. This study provides valuable insights into the molecular characteristics and immune microenvironment of pterygium. The identification of potential biomarkers FN1 and SPRR1B highlights their significance in pterygium pathogenesis and lays a foundation for further exploration aimed at integrating these findings into clinical practice. © The Author(s) 2025.